Class: Cucumber::Glue::RegistryAndMore
- Inherits:
-
Object
- Object
- Cucumber::Glue::RegistryAndMore
- Includes:
- Messages::Helpers::TimeConversion
- 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(type, hook) ⇒ Object
- #after_all ⇒ 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(type, scenario) ⇒ Object
:nodoc:.
-
#initialize(runtime, configuration) ⇒ RegistryAndMore
constructor
A new instance of RegistryAndMore.
- #install_plugin(configuration, registry) ⇒ Object
- #load_code_file(code_file) ⇒ Object
- #register_rb_hook(type, tag_expressions, proc, name: nil) ⇒ Object
- #register_rb_step_definition(string_or_regexp, proc_or_sym, options) ⇒ Object
- #step_matches(name_to_match) ⇒ Object
Constructor Details
#initialize(runtime, configuration) ⇒ RegistryAndMore
Returns a new instance of RegistryAndMore.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 72 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.
52 53 54 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 52 def current_world @current_world end |
#step_definitions ⇒ Object (readonly)
Returns the value of attribute step_definitions.
52 53 54 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 52 def step_definitions @step_definitions end |
Class Method Details
.cli_snippet_type_options ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 64 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(type, hook) ⇒ Object
185 186 187 188 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 185 def add_hook(type, hook) hooks[type.to_sym] << hook hook end |
#after_all ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 173 def after_all set_up_world_for_global_hooks all_succeeded = true # Run each `AfterAll` hook. Ensuring that we store the overall result as the worst status hooks[:after_all].each do |hook| result = invoke_run_hook(hook, 'AfterAll') all_succeeded = false unless result end @current_world = nil all_succeeded end |
#before_all ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 161 def before_all set_up_world_for_global_hooks all_succeeded = true # Run each `BeforeAll` hook. Ensuring that we store the overall result as the worst status hooks[:before_all].each do |hook| result = invoke_run_hook(hook, 'BeforeAll') all_succeeded = false unless result end @current_world = nil all_succeeded end |
#begin_scenario(test_case) ⇒ Object
144 145 146 147 148 149 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 144 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
122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 122 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
190 191 192 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 190 def clear_hooks @hooks = nil end |
#create_expression(string_or_regexp) ⇒ Object
198 199 200 201 202 203 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 198 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
97 98 99 100 101 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 97 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
151 152 153 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 151 def end_scenario @current_world = nil end |
#hooks_for(type, scenario) ⇒ Object
:nodoc:
194 195 196 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 194 def hooks_for(type, scenario) # :nodoc: hooks[type.to_sym].select { |hook| scenario.accept_hook?(hook) } end |
#install_plugin(configuration, registry) ⇒ Object
155 156 157 158 159 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 155 def install_plugin(configuration, registry) hooks[:install_plugin].each do |hook| hook.invoke('InstallPlugin', [configuration, registry]) end end |
#load_code_file(code_file) ⇒ Object
137 138 139 140 141 142 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 137 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 require File.(code_file) end |
#register_rb_hook(type, tag_expressions, proc, name: nil) ⇒ Object
91 92 93 94 95 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 91 def register_rb_hook(type, tag_expressions, proc, name: nil) hook = add_hook(type, Hook.new(@configuration.id_generator.new_id, self, tag_expressions, proc, name: name)) @configuration.notify(:envelope, hook.to_envelope(type)) hook end |
#register_rb_step_definition(string_or_regexp, proc_or_sym, options) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 103 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 @configuration.notify(:undefined_parameter_type, e.undefined_parameter_type_name, string_or_regexp) # Move the below code into cucumber-expressions. Once done. Switch the line for # @configuration.notify(:envelope, e.to_envelope(string_or_regexp)) to_envelope = Cucumber::Messages::Envelope.new( undefined_parameter_type: Cucumber::Messages::UndefinedParameterType.new( name: e.undefined_parameter_type_name, expression: string_or_regexp ) ) @configuration.notify(:envelope, to_envelope) end |
#step_matches(name_to_match) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/cucumber/glue/registry_and_more.rb', line 83 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 |