class Cucumber::Runtime::SupportCode
Public Class Methods
new(user_interface, configuration={})
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 46 def initialize(user_interface, configuration={}) @configuration = Configuration.new(configuration) @runtime_facade = Runtime::ForProgrammingLanguages.new(self, user_interface) @unsupported_programming_languages = [] @programming_languages = [] @language_map = {} end
Public Instance Methods
apply_after_hooks(test_case)
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 166 def apply_after_hooks(test_case) ruby = load_programming_language('rb') scenario = RunningTestCase.new(test_case) hooks = ruby.hooks_for(:after, scenario) AfterHooks.new(hooks, scenario).apply_to(test_case) end
apply_before_hooks(test_case)
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 159 def apply_before_hooks(test_case) ruby = load_programming_language('rb') scenario = RunningTestCase.new(test_case) hooks = ruby.hooks_for(:before, scenario) BeforeHooks.new(hooks, scenario).apply_to(test_case) end
configure(new_configuration)
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 54 def configure(new_configuration) @configuration = Configuration.new(new_configuration) end
find_after_step_hooks(test_case)
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 152 def find_after_step_hooks(test_case) ruby = load_programming_language('rb') scenario = RunningTestCase.new(test_case) hooks = ruby.hooks_for(:after_step, scenario) StepHooks.new hooks end
find_around_hooks(test_case)
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 173 def find_around_hooks(test_case) ruby = load_programming_language('rb') scenario = RunningTestCase.new(test_case) ruby.hooks_for(:around, scenario).map do |hook| Hooks.around_hook(test_case.source) do |run_scenario| hook.invoke('Around', scenario, &run_scenario) end end end
find_match(test_step)
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 138 def find_match(test_step) begin match = step_match(test_step.name) rescue Cucumber::Undefined return NoStepMatch.new(test_step.source.last, test_step.name) end # TODO: move this onto Filters::ActivateSteps @configuration.notify Events::StepMatch.new(test_step, match) if @configuration.dry_run? return SkippingStepMatch.new end match end
fire_hook(name, *args)
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 126 def fire_hook(name, *args) @programming_languages.each do |programming_language| programming_language.send(name, *args) end end
invoke_dynamic_step(step_name, multiline_argument, location=nil)
click to toggle source
@api private This allows users to attempt to find, match and execute steps from code as the features are running, as opposed to regular steps which are compiled into test steps before execution.
These are commonly called nested steps.
# File lib/cucumber/runtime/support_code.rb, line 75 def invoke_dynamic_step(step_name, multiline_argument, location=nil) begin step_match(step_name).invoke(multiline_argument) rescue Undefined => exception raise UndefinedDynamicStep, step_name end end
invoke_dynamic_steps(steps_text, i18n, location)
click to toggle source
Invokes a series of steps steps_text
. Example:
invoke(%Q{ Given I have 8 cukes in my belly Then I should not be thirsty })
# File lib/cucumber/runtime/support_code.rb, line 64 def invoke_dynamic_steps(steps_text, i18n, location) parser = Cucumber::Gherkin::StepsParser.new(StepInvoker.new(self), i18n.iso_code) parser.parse(steps_text) end
load_files!(files)
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 96 def load_files!(files) log.debug("Code:\n") files.each do |file| load_file(file) end log.debug("\n") end
load_files_from_paths(paths)
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 104 def load_files_from_paths(paths) files = paths.map { |path| Dir["#{path}/**/*"] }.flatten load_files! files end
load_programming_language(ext)
click to toggle source
Loads and registers programming language implementation. Instances are cached, so calling with the same argument twice will return the same instance.
# File lib/cucumber/runtime/support_code.rb, line 87 def load_programming_language(ext) return @language_map[ext] if @language_map[ext] programming_language_class = constantize("Cucumber::#{ext.capitalize}Support::#{ext.capitalize}Language") programming_language = programming_language_class.new(@runtime_facade) @programming_languages << programming_language @language_map[ext] = programming_language programming_language end
step_definitions()
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 132 def step_definitions @programming_languages.map do |programming_language| programming_language.step_definitions end.flatten end
unknown_programming_language?()
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 122 def unknown_programming_language? @programming_languages.empty? end
unmatched_step_definitions()
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 109 def unmatched_step_definitions @programming_languages.map do |programming_language| programming_language.unmatched_step_definitions end.flatten end
Private Instance Methods
guess_step_matches?()
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 203 def guess_step_matches? @configuration.guess? end
load_file(file)
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 229 def load_file(file) if programming_language = programming_language_for(file) log.debug(" * #{file}\n") programming_language.load_code_file(file) else log.debug(" * #{file} [NOT SUPPORTED]\n") end end
log()
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 238 def log Cucumber.logger end
matches(step_name, name_to_report)
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 207 def matches(step_name, name_to_report) @programming_languages.map do |programming_language| programming_language.step_matches(step_name, name_to_report).to_a end.flatten end
programming_language_for(step_def_file)
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 242 def programming_language_for(step_def_file) if ext = File.extname(step_def_file)[1..-1] return nil if @unsupported_programming_languages.index(ext) begin load_programming_language(ext) rescue LoadError => e log.debug("Failed to load '#{ext}' programming language for file #{step_def_file}: #{e.message}\n") @unsupported_programming_languages << ext nil end else nil end end
step_match_without_cache(step_name, name_to_report=nil)
click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 195 def step_match_without_cache(step_name, name_to_report=nil) matches = matches(step_name, name_to_report) raise Undefined.new(step_name) if matches.empty? matches = best_matches(step_name, matches) if matches.size > 1 && guess_step_matches? raise Ambiguous.new(step_name, matches, guess_step_matches?) if matches.size > 1 matches[0] end