Class: Cucumber::Runtime::SupportCode

Inherits:
Object
  • Object
show all
Includes:
Constantize
Defined in:
lib/cucumber/runtime/support_code.rb

Defined Under Namespace

Classes: StepInvoker

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Constantize

#constantize, #underscore

Constructor Details

#initialize(user_interface, configuration = Configuration.default) ⇒ SupportCode

Returns a new instance of SupportCode.



51
52
53
54
55
56
# File 'lib/cucumber/runtime/support_code.rb', line 51

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

Instance Attribute Details

#registryObject (readonly)

Returns the value of attribute registry.



49
50
51
# File 'lib/cucumber/runtime/support_code.rb', line 49

def registry
  @registry
end

Instance Method Details

#apply_after_hooks(test_case) ⇒ Object



123
124
125
126
127
# File 'lib/cucumber/runtime/support_code.rb', line 123

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) ⇒ Object



117
118
119
120
121
# File 'lib/cucumber/runtime/support_code.rb', line 117

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) ⇒ Object



58
59
60
# File 'lib/cucumber/runtime/support_code.rb', line 58

def configure(new_configuration)
  @configuration = Configuration.new(new_configuration)
end

#find_after_step_hooks(test_case) ⇒ Object



111
112
113
114
115
# File 'lib/cucumber/runtime/support_code.rb', line 111

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) ⇒ Object



129
130
131
132
133
134
135
136
137
# File 'lib/cucumber/runtime/support_code.rb', line 129

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) ⇒ Object



102
103
104
105
# File 'lib/cucumber/runtime/support_code.rb', line 102

def fire_hook(name, *args)
  # TODO: kill with fire
  registry.send(name, *args)
end

#invoke_dynamic_step(step_name, multiline_argument, _location = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



79
80
81
82
83
# File 'lib/cucumber/runtime/support_code.rb', line 79

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) ⇒ Object

Invokes a series of steps steps_text. Example:

invoke(%Q{
  Given I have 8 cukes in my belly
  Then I should not be thirsty
})


68
69
70
71
# File 'lib/cucumber/runtime/support_code.rb', line 68

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) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/cucumber/runtime/support_code.rb', line 85

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) ⇒ Object



93
94
95
96
# File 'lib/cucumber/runtime/support_code.rb', line 93

def load_files_from_paths(paths)
  files = paths.map { |path| Dir["#{path}/**/*.rb"] }.flatten
  load_files! files
end

#step_definitionsObject



107
108
109
# File 'lib/cucumber/runtime/support_code.rb', line 107

def step_definitions
  registry.step_definitions
end

#unmatched_step_definitionsObject



98
99
100
# File 'lib/cucumber/runtime/support_code.rb', line 98

def unmatched_step_definitions
  registry.unmatched_step_definitions
end