Class: Cucumber::Glue::RegistryAndMore
- Inherits:
-
Object
- Object
- Cucumber::Glue::RegistryAndMore
- Defined in:
- lib/cucumber/glue/registry_and_more.rb
Overview
TODO: This class has too many responsibilities, split off
Instance Attribute Summary collapse
-
#current_world ⇒ Object
readonly
Returns the value of attribute current_world.
-
#step_definitions ⇒ Object
readonly
Returns the value of attribute step_definitions.
Class Method Summary collapse
Instance Method Summary collapse
- #add_hook(phase, hook) ⇒ Object
- #after_all ⇒ Object
- #available_step_definition(regexp_source, file_colon_line) ⇒ Object
- #before_all ⇒ Object
- #begin_scenario(test_case) ⇒ Object
- #build_rb_world_factory(world_modules, namespaced_world_modules, proc) ⇒ Object
- #clear_hooks ⇒ Object
- #create_expression(string_or_regexp) ⇒ Object
- #define_parameter_type(parameter_type) ⇒ Object
- #end_scenario ⇒ Object
-
#hooks_for(phase, scenario) ⇒ Object
:nodoc:.
-
#initialize(runtime, configuration) ⇒ RegistryAndMore
constructor
A new instance of RegistryAndMore.
- #install_plugin(configuration, registry) ⇒ Object
- #invoked_step_definition(regexp_source, file_colon_line) ⇒ Object
- #load_code_file(code_file) ⇒ Object
- #register_rb_hook(phase, tag_expressions, proc, name: nil) ⇒ Object
- #register_rb_step_definition(string_or_regexp, proc_or_sym, options) ⇒ Object
- #step_matches(name_to_match) ⇒ Object
- #unmatched_step_definitions ⇒ Object
Constructor Details
#initialize(runtime, configuration) ⇒ RegistryAndMore
Returns a new instance of RegistryAndMore.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 57 def initialize(runtime, configuration) @runtime = runtime @configuration = configuration @step_definitions = [] Glue::Dsl.rb_language = self @world_proc = @world_modules = nil @parameter_type_registry = CucumberExpressions::ParameterTypeRegistry.new cucumber_expression_generator = CucumberExpressions::CucumberExpressionGenerator.new(@parameter_type_registry) @configuration.register_snippet_generator(Snippet::Generator.new(cucumber_expression_generator)) end |
Instance Attribute Details
#current_world ⇒ Object (readonly)
Returns the value of attribute current_world.
46 47 48 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 46 def current_world @current_world end |
#step_definitions ⇒ Object (readonly)
Returns the value of attribute step_definitions.
46 47 48 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 46 def step_definitions @step_definitions end |
Class Method Details
.cli_snippet_type_options ⇒ Object
190 191 192 193 194 195 196 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 190 def self. registry = CucumberExpressions::ParameterTypeRegistry.new cucumber_expression_generator = CucumberExpressions::CucumberExpressionGenerator.new(registry) Snippet::SNIPPET_TYPES.keys.sort_by(&:to_s).map do |type| Snippet::SNIPPET_TYPES[type].cli_option_string(type, cucumber_expression_generator) end end |
Instance Method Details
#add_hook(phase, hook) ⇒ Object
158 159 160 161 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 158 def add_hook(phase, hook) hooks[phase.to_sym] << hook hook end |
#after_all ⇒ Object
152 153 154 155 156 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 152 def after_all hooks[:after_all].each do |hook| hook.invoke('AfterAll', []) end end |
#available_step_definition(regexp_source, file_colon_line) ⇒ Object
175 176 177 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 175 def available_step_definition(regexp_source, file_colon_line) available_step_definition_hash[StepDefinitionLight.new(regexp_source, file_colon_line)] = nil end |
#before_all ⇒ Object
146 147 148 149 150 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 146 def before_all hooks[:before_all].each do |hook| hook.invoke('BeforeAll', []) end end |
#begin_scenario(test_case) ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 128 def begin_scenario(test_case) @current_world = WorldFactory.new(@world_proc).create_world @current_world.extend(ProtoWorld.for(@runtime, test_case.language)) MultiTest.extend_with_best_assertion_library(@current_world) @current_world.add_modules!(@world_modules || [], @namespaced_world_modules || {}) end |
#build_rb_world_factory(world_modules, namespaced_world_modules, proc) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 101 def build_rb_world_factory(world_modules, namespaced_world_modules, proc) if proc raise MultipleWorld.new(@world_proc, proc) if @world_proc @world_proc = proc end @world_modules ||= [] @world_modules += world_modules @namespaced_world_modules ||= Hash.new { |h, k| h[k] = [] } namespaced_world_modules.each do |namespace, world_module| @namespaced_world_modules[namespace] << world_module unless @namespaced_world_modules[namespace].include?(world_module) end end |
#clear_hooks ⇒ Object
163 164 165 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 163 def clear_hooks @hooks = nil end |
#create_expression(string_or_regexp) ⇒ Object
183 184 185 186 187 188 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 183 def create_expression(string_or_regexp) return CucumberExpressions::CucumberExpression.new(string_or_regexp, @parameter_type_registry) if string_or_regexp.is_a?(String) return CucumberExpressions::RegularExpression.new(string_or_regexp, @parameter_type_registry) if string_or_regexp.is_a?(Regexp) raise ArgumentError, 'Expression must be a String or Regexp' end |
#define_parameter_type(parameter_type) ⇒ Object
82 83 84 85 86 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 82 def define_parameter_type(parameter_type) @configuration.notify :envelope, parameter_type_envelope(parameter_type) @parameter_type_registry.define_parameter_type(parameter_type) end |
#end_scenario ⇒ Object
136 137 138 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 136 def end_scenario @current_world = nil end |
#hooks_for(phase, scenario) ⇒ Object
:nodoc:
167 168 169 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 167 def hooks_for(phase, scenario) # :nodoc: hooks[phase.to_sym].select { |hook| scenario.accept_hook?(hook) } end |
#install_plugin(configuration, registry) ⇒ Object
140 141 142 143 144 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 140 def install_plugin(configuration, registry) hooks[:install_plugin].each do |hook| hook.invoke('InstallPlugin', [configuration, registry]) end end |
#invoked_step_definition(regexp_source, file_colon_line) ⇒ Object
179 180 181 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 179 def invoked_step_definition(regexp_source, file_colon_line) invoked_step_definition_hash[StepDefinitionLight.new(regexp_source, file_colon_line)] = nil end |
#load_code_file(code_file) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 116 def load_code_file(code_file) return unless File.extname(code_file) == '.rb' # This will cause self.add_step_definition, self.add_hook, and self.define_parameter_type to be called from Glue::Dsl if Cucumber.use_legacy_autoloader load File.(code_file) else require File.(code_file) end end |
#register_rb_hook(phase, tag_expressions, proc, name: nil) ⇒ Object
76 77 78 79 80 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 76 def register_rb_hook(phase, tag_expressions, proc, name: nil) hook = add_hook(phase, Hook.new(@configuration.id_generator.new_id, self, tag_expressions, proc, name: name)) @configuration.notify :envelope, hook.to_envelope hook end |
#register_rb_step_definition(string_or_regexp, proc_or_sym, options) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 88 def register_rb_step_definition(string_or_regexp, proc_or_sym, ) step_definition = StepDefinition.new(@configuration.id_generator.new_id, self, string_or_regexp, proc_or_sym, ) @step_definitions << step_definition @configuration.notify :step_definition_registered, step_definition @configuration.notify :envelope, step_definition.to_envelope step_definition rescue Cucumber::CucumberExpressions::UndefinedParameterTypeError => e # TODO: add a way to extract the parameter type directly from the error. type_name = e..match(/^Undefined parameter type ['|{](.*)['|}].?$/)[1] @configuration.notify :undefined_parameter_type, type_name, string_or_regexp end |
#step_matches(name_to_match) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 68 def step_matches(name_to_match) @step_definitions.each_with_object([]) do |step_definition, result| if (arguments = step_definition.arguments_from(name_to_match)) result << StepMatch.new(step_definition, name_to_match, arguments) end end end |
#unmatched_step_definitions ⇒ Object
171 172 173 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 171 def unmatched_step_definitions available_step_definition_hash.keys - invoked_step_definition_hash.keys end |