class Cucumber::RbSupport::RbLanguage

The Ruby implementation of the programming language API.

Attributes

current_world[R]
step_definitions[R]

Public Class Methods

new(runtime, configuration) click to toggle source
# 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

Private Class Methods

cli_snippet_type_options() click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 204
def self.cli_snippet_type_options
  Snippet::SNIPPET_TYPES.keys.sort_by(&:to_s).map do |type|
    Snippet::SNIPPET_TYPES[type].cli_option_string(type)
  end
end

Public Instance Methods

add_hook(phase, hook) click to toggle source
# 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) click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 129
def add_transform(transform)
  transforms.unshift transform
  transform
end
after_configuration(configuration) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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_hooks() click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 125
def clear_hooks
  @hooks = nil
end
end_scenario() click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 103
def end_scenario
  @current_world = nil
end
execute_transforms(args) click to toggle source
# 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
invoked_step_definition(regexp_source, file_colon_line) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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_definitions() click to toggle source
# 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

Private Instance Methods

available_step_definition_hash() click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 152
def available_step_definition_hash
  @available_step_definition_hash ||= {}
end
check_nil(o, proc) click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 190
def check_nil(o, proc)
  if o.nil?
    begin
      raise NilWorld.new
    rescue NilWorld => e
      e.backtrace.clear
      e.backtrace.push(RbSupport.backtrace_line(proc, "World"))
      raise e
    end
  else
    o
  end
end
connect_world(scenario) click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 185
def connect_world(scenario)
  @current_world.__cucumber_runtime = @runtime
  @current_world.__natural_language = scenario.language
end
create_world() click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 168
def create_world
  if(@world_proc)
    @current_world = @world_proc.call
    check_nil(@current_world, @world_proc)
  else
    @current_world = Object.new
  end
end
extend_world() click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 177
def extend_world
  @current_world.extend(RbWorld)
  MultiTest.extend_with_best_assertion_library(@current_world)
  (@world_modules || []).each do |mod|
    @current_world.extend(mod)
  end
end
hooks() click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 160
def hooks
  @hooks ||= Hash.new{|h,k| h[k] = []}
end
invoked_step_definition_hash() click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 156
def invoked_step_definition_hash
  @invoked_step_definition_hash ||= {}
end
transforms() click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 164
def transforms
  @transforms ||= []
end