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


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

def initialize(runtime, configuration)
  @runtime, @configuration = runtime, 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


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

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


128
129
130
131
# File 'lib/cucumber/glue/registry_and_more.rb', line 128

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

#after_configuration(configuration) ⇒ Object


122
123
124
125
126
# File 'lib/cucumber/glue/registry_and_more.rb', line 122

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


145
146
147
# File 'lib/cucumber/glue/registry_and_more.rb', line 145

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


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

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
102
103
# 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|
    unless @namespaced_world_modules[namespace].include?(world_module)
      @namespaced_world_modules[namespace] << world_module
    end
  end
end

#clear_hooksObject


133
134
135
# File 'lib/cucumber/glue/registry_and_more.rb', line 133

def clear_hooks
  @hooks = nil
end

#create_expression(string_or_regexp) ⇒ Object

Raises:

  • (ArgumentError)

153
154
155
156
157
# File 'lib/cucumber/glue/registry_and_more.rb', line 153

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.new('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


118
119
120
# File 'lib/cucumber/glue/registry_and_more.rb', line 118

def end_scenario
  @current_world = nil
end

#hooks_for(phase, scenario) ⇒ Object

:nodoc:


137
138
139
# File 'lib/cucumber/glue/registry_and_more.rb', line 137

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


149
150
151
# File 'lib/cucumber/glue/registry_and_more.rb', line 149

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


105
106
107
108
# File 'lib/cucumber/glue/registry_and_more.rb', line 105

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


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

def step_matches(name_to_match)
  @step_definitions.reduce([]) do |result, step_definition|
    if (arguments = step_definition.arguments_from(name_to_match))
      result << StepMatch.new(step_definition, name_to_match, arguments)
    end
    result
  end
end

#unmatched_step_definitionsObject


141
142
143
# File 'lib/cucumber/glue/registry_and_more.rb', line 141

def unmatched_step_definitions
  available_step_definition_hash.keys - invoked_step_definition_hash.keys
end