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

Instance Method Summary collapse

Constructor Details

#initialize(runtime, configuration) ⇒ RegistryAndMore

Returns a new instance of RegistryAndMore.



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

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.



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

def current_world
  @current_world
end

#step_definitionsObject (readonly)

Returns the value of attribute step_definitions.



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

def step_definitions
  @step_definitions
end

Instance Method Details

#add_hook(phase, hook) ⇒ Object



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

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

#after_configuration(configuration) ⇒ Object



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

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



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

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



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

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



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

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



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

def clear_hooks
  @hooks = nil
end

#create_expression(string_or_regexp) ⇒ Object

Raises:

  • (ArgumentError)


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

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



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

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

#end_scenarioObject



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

def end_scenario
  @current_world = nil
end

#hooks_for(phase, scenario) ⇒ Object

:nodoc:



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

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



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

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



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

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



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

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



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

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



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

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

#unmatched_step_definitionsObject



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

def unmatched_step_definitions
  available_step_definition_hash.keys - invoked_step_definition_hash.keys
end