Skip to content

Commit

Permalink
Merge branch 'mattwynne/clean_up_step_mother'
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Sep 13, 2010
2 parents 4ae9b36 + 8e91099 commit 8f21b0c
Show file tree
Hide file tree
Showing 25 changed files with 771 additions and 775 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -20,3 +20,4 @@ target
*.rbc
rerun.txt
._*
.rvmrc
4 changes: 2 additions & 2 deletions lib/cucumber/ast/tree_walker.rb
Expand Up @@ -5,8 +5,8 @@ class TreeWalker
attr_accessor :configuration #:nodoc:
attr_reader :step_mother #:nodoc:

def initialize(step_mother, listeners = [], configuration = Cucumber::Configuration.default, io = STDOUT)
@step_mother, @listeners, @configuration, @io = step_mother, listeners, configuration, io
def initialize(step_mother, listeners = [], configuration = Cucumber::Configuration.default)
@step_mother, @listeners, @configuration = step_mother, listeners, configuration
end

def visit_features(features)
Expand Down
12 changes: 6 additions & 6 deletions lib/cucumber/cli/configuration.rb
Expand Up @@ -64,8 +64,8 @@ def expand?
@options[:expand]
end

def build_runner(step_mother, io)
Ast::TreeWalker.new(step_mother, formatters(step_mother), self, io)
def build_tree_walker(step_mother)
Ast::TreeWalker.new(step_mother, formatters(step_mother), self)
end

def formatter_class(format)
Expand Down Expand Up @@ -146,7 +146,10 @@ def options
warn("Deprecated: Configuration#options will be removed from the next release of Cucumber. Please use the configuration object directly instead.")
@options
end


def paths
@options[:paths].empty? ? ['features'] : @options[:paths]
end
private

def formatters(step_mother)
Expand Down Expand Up @@ -176,9 +179,6 @@ def call(severity, time, progname, msg)
end
end

def paths
@options[:paths].empty? ? ['features'] : @options[:paths]
end

def set_environment_variables
@options[:env_vars].each do |var, value|
Expand Down
41 changes: 2 additions & 39 deletions lib/cucumber/cli/main.rb
Expand Up @@ -22,43 +22,6 @@ def run_tests(argv, stderr, stdout)
end

module Cucumber
class Runtime
class Result
def initialize(failure)
@failure = failure
end
def failure?
@failure
end
end

def initialize(configuration)
@configuration = configuration
end

def run
step_mother = StepMother.new(@configuration)
step_mother.load_code_files(@configuration.support_to_load)
step_mother.after_configuration(@configuration)
features = step_mother.load_plain_text_features(@configuration.feature_files)
step_mother.load_code_files(@configuration.step_defs_to_load)

runner = @configuration.build_runner(step_mother, @out_stream)
step_mother.visitor = runner # Needed to support World#announce

runner.visit_features(features)

failure = if @configuration.wip?
step_mother.scenarios(:passed).any?
else
step_mother.scenarios(:failed).any? ||
(@configuration.strict? && (step_mother.steps(:undefined).any? || step_mother.steps(:pending).any?))
end

Result.new(failure)
end
end

module Cli
class Main
class << self
Expand Down Expand Up @@ -88,8 +51,8 @@ def execute!(legacy_step_mother = nil)
return @drb_output if run_drb_client

runtime = Runtime.new(configuration)
result = runtime.run
result.failure?
runtime.run!
runtime.results.failure?
rescue ProfilesNotDefinedError, YmlLoadError, ProfileNotFound => e
@error_stream.puts e.message
true
Expand Down
4 changes: 4 additions & 0 deletions lib/cucumber/configuration.rb
Expand Up @@ -24,5 +24,9 @@ def strict?
def expand?
@options[:expand]
end

def paths
@options[:paths]
end
end
end
8 changes: 4 additions & 4 deletions lib/cucumber/js_support/js_dsl.js
@@ -1,15 +1,15 @@
var CucumberJsDsl = {
registerStepDefinition: function(regexp, func) {
if(func == null) {
jsLanguage.executeStepDefinition(regexp);
jsLanguage.execute_step_definition(regexp);
}
else{
jsLanguage.addStepDefinition(regexp, func);
jsLanguage.add_step_definition(regexp, func);
}
},

registerTransform: function(regexp, func) {
jsLanguage.registerJsTransform(regexp, func);
jsLanguage.register_js_transform(regexp, func);
},

beforeHook: function(tag_expressions_or_func, func) {
Expand Down Expand Up @@ -40,7 +40,7 @@ var CucumberJsDsl = {
var hook_func = tag_expressions_or_func;
var tag_expressions = [];
}
jsLanguage.registerJsHook(label, tag_expressions, hook_func);
jsLanguage.register_js_hook(label, tag_expressions, hook_func);
}
}

Expand Down
10 changes: 5 additions & 5 deletions lib/cucumber/js_support/js_language.rb
Expand Up @@ -105,10 +105,10 @@ class JsLanguage
include LanguageSupport::LanguageMethods
include JsSnippets

def initialize(step_mother)
def initialize(runtime)
@step_definitions = []
@world = JsWorld.new
@step_mother = step_mother
@runtime = runtime

@world["jsLanguage"] = self
@world.load(File.dirname(__FILE__) + '/js_dsl.js')
Expand Down Expand Up @@ -150,7 +150,7 @@ def add_step_definition(regexp, js_function)

#TODO: support multiline arguments when calling steps from within steps
def execute_step_definition(name, multiline_argument = nil)
@step_mother.step_match(name).invoke(multiline_argument)
@runtime.step_match(name).invoke(multiline_argument)
end

def register_js_hook(phase, tag_expressions, js_function)
Expand All @@ -166,12 +166,12 @@ def current_world
end

def steps(steps_text, file_colon_line)
@step_mother.invoke_steps(steps_text, @language, file_colon_line)
@runtime.invoke_steps(steps_text, @language, file_colon_line)
end

private
def path_to_load_js_from
paths = @step_mother.options[:paths]
paths = @runtime.features_paths
if paths.empty?
'' # Using rake
else
Expand Down
214 changes: 214 additions & 0 deletions lib/cucumber/runtime.rb
@@ -0,0 +1,214 @@
require 'cucumber/configuration'
require 'cucumber/constantize'
require 'cucumber/core_ext/instance_exec'
require 'cucumber/language_support/language_methods'
require 'cucumber/formatter/duration'
require 'cucumber/cli/options'
require 'cucumber/errors'
require 'gherkin/rubify'
require 'timeout'
require 'cucumber/runtime/user_interface'
require 'cucumber/runtime/features_loader'
require 'cucumber/runtime/results'
require 'cucumber/runtime/support_code'

module Cucumber
# This is the meaty part of Cucumber that ties everything together.
class Runtime
attr_reader :results

include Formatter::Duration
include Runtime::UserInterface

def initialize(configuration = Configuration.default)
@current_scenario = nil
@configuration = parse_configuration(configuration)
@support_code = SupportCode.new(self, @configuration.guess?)
@results = Results.new(@configuration)
end

def run!
load_support
fire_after_configuration_hook
load_step_definitions

tree_walker = @configuration.build_tree_walker(self)
self.visitor = tree_walker # Ugly circular dependency, but needed to support World#announce

tree_walker.visit_features(features)
end

def features_paths
@configuration.paths
end

def step_visited(step) #:nodoc:
@results.step_visited(step)
end

def scenarios(status = nil)
@results.scenarios(status)
end

def steps(status = nil)
@results.steps(status)
end

# Loads and registers programming language implementation.
# Instances are cached, so calling with the same argument
# twice will return the same instance.
#
def load_programming_language(ext)
@support_code.load_programming_language!(ext)
end

def invoke(step_name, multiline_argument)
@support_code.invoke(step_name, multiline_argument)
end

# Invokes a series of steps +steps_text+. Example:
#
# invoke(%Q{
# Given I have 8 cukes in my belly
# Then I should not be thirsty
# })
def invoke_steps(steps_text, i18n, file_colon_line)
@support_code.invoke_steps(steps_text, i18n, file_colon_line)
end

# Returns a Cucumber::Ast::Table for +text_or_table+, which can either
# be a String:
#
# table(%{
# | account | description | amount |
# | INT-100 | Taxi | 114 |
# | CUC-101 | Peeler | 22 |
# })
#
# or a 2D Array:
#
# table([
# %w{ account description amount },
# %w{ INT-100 Taxi 114 },
# %w{ CUC-101 Peeler 22 }
# ])
#
def table(text_or_table, file=nil, line_offset=0)
if Array === text_or_table
Ast::Table.new(text_or_table)
else
Ast::Table.parse(text_or_table, file, line_offset)
end
end

# Returns a regular String for +string_with_triple_quotes+. Example:
#
# """
# hello
# world
# """
#
# Is retured as: " hello\nworld"
#
def py_string(string_with_triple_quotes, file=nil, line_offset=0)
Ast::PyString.parse(string_with_triple_quotes)
end

def step_match(step_name, name_to_report=nil) #:nodoc:
@support_code.step_match(step_name, name_to_report)
end

def unmatched_step_definitions
@support_code.unmatched_step_definitions
end

def snippet_text(step_keyword, step_name, multiline_arg_class) #:nodoc:
@support_code.snippet_text(step_keyword, step_name, multiline_arg_class)
end

def with_hooks(scenario, skip_hooks=false)
around(scenario, skip_hooks) do
before_and_after(scenario, skip_hooks) do
yield scenario
end
end
end

def around(scenario, skip_hooks=false, &block) #:nodoc:
if skip_hooks
yield
return
end

@support_code.around(scenario, block)
end

def before_and_after(scenario, skip_hooks=false) #:nodoc:
before(scenario) unless skip_hooks
yield scenario
after(scenario) unless skip_hooks
@results.scenario_visited(scenario)
end

def before(scenario) #:nodoc:
return if @configuration.dry_run? || @current_scenario
@current_scenario = scenario
@support_code.fire_hook(:before, scenario)
end

def after(scenario) #:nodoc:
@current_scenario = nil
return if @configuration.dry_run?
@support_code.fire_hook(:after, scenario)
end

def after_step #:nodoc:
return if @configuration.dry_run?
@support_code.fire_hook(:execute_after_step, @current_scenario)
end

def unknown_programming_language?
@support_code.unknown_programming_language?
end

private

def fire_after_configuration_hook #:nodoc
@support_code.fire_hook(:after_configuration, @configuration)
end

def features
loader = Runtime::FeaturesLoader.new(
@configuration.feature_files,
@configuration.filters,
@configuration.tag_expression)
loader.features
end

def load_support
load_code_files(@configuration.support_to_load)
end

def load_step_definitions
load_code_files(@configuration.step_defs_to_load)
end

def load_code_files(step_def_files)
@support_code.load_files!(step_def_files)
end

def log
Cucumber.logger
end

def parse_configuration(configuration_argument)
case configuration_argument
when Hash
Configuration.new(configuration_argument)
else
configuration_argument
end
end
end

end

0 comments on commit 8f21b0c

Please sign in to comment.