Class: Cucumber::RbSupport::RbLanguage

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/rb_support/rb_language.rb

Overview

The Ruby implementation of the programming language API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime, configuration) ⇒ RbLanguage

Returns a new instance of RbLanguage.



48
49
50
51
52
53
54
# File 'lib/cucumber/rb_support/rb_language.rb', line 48

def initialize(runtime, configuration)
  @runtime = runtime
  @step_definitions = []
  RbDsl.rb_language = self
  @world_proc = @world_modules = nil
  configuration.register_snippet_generator(Snippet::Generator.new)
end

Instance Attribute Details

#current_worldObject (readonly)

Returns the value of attribute current_world.



37
38
39
# File 'lib/cucumber/rb_support/rb_language.rb', line 37

def current_world
  @current_world
end

#step_definitionsObject (readonly)

Returns the value of attribute step_definitions.



37
38
39
# File 'lib/cucumber/rb_support/rb_language.rb', line 37

def step_definitions
  @step_definitions
end

Instance Method Details

#add_hook(phase, hook) ⇒ Object



120
121
122
123
# File 'lib/cucumber/rb_support/rb_language.rb', line 120

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

#add_transform(transform) ⇒ Object



129
130
131
132
# File 'lib/cucumber/rb_support/rb_language.rb', line 129

def add_transform(transform)
  transforms.unshift transform
  transform
end

#after_configuration(configuration) ⇒ Object



107
108
109
110
111
# File 'lib/cucumber/rb_support/rb_language.rb', line 107

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



142
143
144
# File 'lib/cucumber/rb_support/rb_language.rb', line 142

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

#begin_rb_scenario(scenario) ⇒ Object



65
66
67
68
69
# File 'lib/cucumber/rb_support/rb_language.rb', line 65

def begin_rb_scenario(scenario)
  create_world
  extend_world
  connect_world(scenario)
end

#begin_scenario(scenario) ⇒ Object



99
100
101
# File 'lib/cucumber/rb_support/rb_language.rb', line 99

def begin_scenario(scenario)
  begin_rb_scenario(scenario)
end

#build_rb_world_factory(world_modules, proc) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/cucumber/rb_support/rb_language.rb', line 85

def build_rb_world_factory(world_modules, proc)
  if(proc)
    raise MultipleWorld.new(@world_proc, proc) if @world_proc
    @world_proc = proc
  end
  @world_modules ||= []
  @world_modules += world_modules
end

#clear_hooksObject



125
126
127
# File 'lib/cucumber/rb_support/rb_language.rb', line 125

def clear_hooks
  @hooks = nil
end

#end_scenarioObject



103
104
105
# File 'lib/cucumber/rb_support/rb_language.rb', line 103

def end_scenario
  @current_world = nil
end

#execute_transforms(args) ⇒ Object



113
114
115
116
117
118
# File 'lib/cucumber/rb_support/rb_language.rb', line 113

def execute_transforms(args)
  args.map do |arg|
    matching_transform = transforms.detect {|transform| transform.match(arg) }
    matching_transform ? matching_transform.invoke(arg) : arg
  end
end

#hooks_for(phase, scenario) ⇒ Object

:nodoc:



134
135
136
# File 'lib/cucumber/rb_support/rb_language.rb', line 134

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



146
147
148
# File 'lib/cucumber/rb_support/rb_language.rb', line 146

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



94
95
96
97
# File 'lib/cucumber/rb_support/rb_language.rb', line 94

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.add_transform to be called from RbDsl
end

#register_rb_hook(phase, tag_expressions, proc) ⇒ Object



71
72
73
# File 'lib/cucumber/rb_support/rb_language.rb', line 71

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

#register_rb_step_definition(regexp, proc_or_sym, options) ⇒ Object



79
80
81
82
83
# File 'lib/cucumber/rb_support/rb_language.rb', line 79

def register_rb_step_definition(regexp, proc_or_sym, options)
  step_definition = RbStepDefinition.new(self, regexp, proc_or_sym, options)
  @step_definitions << step_definition
  step_definition
end

#register_rb_transform(regexp, proc) ⇒ Object



75
76
77
# File 'lib/cucumber/rb_support/rb_language.rb', line 75

def register_rb_transform(regexp, proc)
  add_transform(RbTransform.new(self, regexp, proc))
end

#step_matches(name_to_match) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/cucumber/rb_support/rb_language.rb', line 56

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



138
139
140
# File 'lib/cucumber/rb_support/rb_language.rb', line 138

def unmatched_step_definitions
  available_step_definition_hash.keys - invoked_step_definition_hash.keys
end