class Cucumber::Runtime::SupportCode

Attributes

registry[R]

Public Class Methods

new(user_interface, configuration = Configuration.default) click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 48
def initialize(user_interface, configuration = Configuration.default)
  @configuration = configuration
  # TODO: needs a better name, or inlining its methods
  @runtime_facade = Runtime::ForProgrammingLanguages.new(self, user_interface)
  @registry = Cucumber::Glue::RegistryAndMore.new(@runtime_facade, @configuration)
end

Public Instance Methods

apply_after_hooks(test_case) click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 120
def apply_after_hooks(test_case)
  scenario = RunningTestCase.new(test_case)
  hooks = registry.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 114
def apply_before_hooks(test_case)
  scenario = RunningTestCase.new(test_case)
  hooks = registry.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 55
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 108
def find_after_step_hooks(test_case)
  scenario = RunningTestCase.new(test_case)
  hooks = registry.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 126
def find_around_hooks(test_case)
  scenario = RunningTestCase.new(test_case)

  registry.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
fire_hook(name, *args) click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 99
def fire_hook(name, *args)
  # TODO: kill with fire
  registry.send(name, *args)
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 76
def invoke_dynamic_step(step_name, multiline_argument, _location = nil)
  matches = step_matches(step_name)
  raise UndefinedDynamicStep, step_name if matches.empty?
  matches.first.invoke(multiline_argument)
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 65
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 82
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 90
def load_files_from_paths(paths)
  files = paths.map { |path| Dir["#{path}/**/*.rb"] }.flatten
  load_files! files
end
step_definitions() click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 104
def step_definitions
  registry.step_definitions
end
unmatched_step_definitions() click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 95
def unmatched_step_definitions
  registry.unmatched_step_definitions
end

Private Instance Methods

load_file(file) click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 142
def load_file(file)
  log.debug("  * #{file}\n")
  registry.load_code_file(file)
end
log() click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 147
def log
  Cucumber.logger
end
step_matches(step_name) click to toggle source
# File lib/cucumber/runtime/support_code.rb, line 138
def step_matches(step_name)
  StepMatchSearch.new(registry.method(:step_matches), @configuration).call(step_name)
end