Class: Cucumber::Glue::RegistryAndMore

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/glue/registry_and_more.rb

Overview

TODO: This class has too many responsibilities, split off

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime, configuration) ⇒ RegistryAndMore

Returns a new instance of RegistryAndMore.


55
56
57
58
59
60
61
62
63
64
# File 'lib/cucumber/glue/registry_and_more.rb', line 55

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_worldObject (readonly)

Returns the value of attribute current_world


44
45
46
# File 'lib/cucumber/glue/registry_and_more.rb', line 44

def current_world
  @current_world
end

#step_definitionsObject (readonly)

Returns the value of attribute step_definitions


44
45
46
# File 'lib/cucumber/glue/registry_and_more.rb', line 44

def step_definitions
  @step_definitions
end

Class Method Details

.cli_snippet_type_optionsObject


157
158
159
160
161
162
163
# File 'lib/cucumber/glue/registry_and_more.rb', line 157

def self.cli_snippet_type_options
  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


126
127
128
129
# File 'lib/cucumber/glue/registry_and_more.rb', line 126

def add_hook(phase, hook)
  hooks[phase.to_sym] << hook
  hook
end

#after_configuration(configuration) ⇒ Object


120
121
122
123
124
# File 'lib/cucumber/glue/registry_and_more.rb', line 120

def after_configuration(configuration)
  hooks[:after_configuration].each do |hook|
    hook.invoke('AfterConfiguration', configuration)
  end
end

#available_step_definition(regexp_source, file_colon_line) ⇒ Object


143
144
145
# File 'lib/cucumber/glue/registry_and_more.rb', line 143

def available_step_definition(regexp_source, file_colon_line)
  available_step_definition_hash[StepDefinitionLight.new(regexp_source, file_colon_line)] = nil
end

#begin_scenario(test_case) ⇒ Object


108
109
110
111
112
113
114
# File 'lib/cucumber/glue/registry_and_more.rb', line 108

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


89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/cucumber/glue/registry_and_more.rb', line 89

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_hooksObject


131
132
133
# File 'lib/cucumber/glue/registry_and_more.rb', line 131

def clear_hooks
  @hooks = nil
end

#create_expression(string_or_regexp) ⇒ Object

Raises:

  • (ArgumentError)

151
152
153
154
155
# File 'lib/cucumber/glue/registry_and_more.rb', line 151

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


78
79
80
# File 'lib/cucumber/glue/registry_and_more.rb', line 78

def define_parameter_type(parameter_type)
  @parameter_type_registry.define_parameter_type(parameter_type)
end

#end_scenarioObject


116
117
118
# File 'lib/cucumber/glue/registry_and_more.rb', line 116

def end_scenario
  @current_world = nil
end

#hooks_for(phase, scenario) ⇒ Object

:nodoc:


135
136
137
# File 'lib/cucumber/glue/registry_and_more.rb', line 135

def hooks_for(phase, scenario) #:nodoc:
  hooks[phase.to_sym].select { |hook| scenario.accept_hook?(hook) }
end

#invoked_step_definition(regexp_source, file_colon_line) ⇒ Object


147
148
149
# File 'lib/cucumber/glue/registry_and_more.rb', line 147

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


103
104
105
106
# File 'lib/cucumber/glue/registry_and_more.rb', line 103

def load_code_file(code_file)
  return unless File.extname(code_file) == '.rb'
  load File.expand_path(code_file) # This will cause self.add_step_definition, self.add_hook, and self.define_parameter_type to be called from Glue::Dsl
end

#register_rb_hook(phase, tag_expressions, proc) ⇒ Object


74
75
76
# File 'lib/cucumber/glue/registry_and_more.rb', line 74

def register_rb_hook(phase, tag_expressions, proc)
  add_hook(phase, Hook.new(self, tag_expressions, proc))
end

#register_rb_step_definition(string_or_regexp, proc_or_sym, options) ⇒ Object


82
83
84
85
86
87
# File 'lib/cucumber/glue/registry_and_more.rb', line 82

def register_rb_step_definition(string_or_regexp, proc_or_sym, options)
  step_definition = StepDefinition.new(self, string_or_regexp, proc_or_sym, options)
  @step_definitions << step_definition
  @configuration.notify :step_definition_registered, step_definition
  step_definition
end

#step_matches(name_to_match) ⇒ Object


66
67
68
69
70
71
72
# File 'lib/cucumber/glue/registry_and_more.rb', line 66

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_definitionsObject


139
140
141
# File 'lib/cucumber/glue/registry_and_more.rb', line 139

def unmatched_step_definitions
  available_step_definition_hash.keys - invoked_step_definition_hash.keys
end