class Cucumber::RbSupport::RbLanguage

The Ruby implementation of the programming language API.

Constants

SNIPPET_TYPES

Attributes

current_world[R]
step_definitions[R]

Public Class Methods

new(runtime) click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 54
def initialize(runtime)
  @runtime = runtime
  @step_definitions = []
  RbDsl.rb_language = self
  @world_proc = @world_modules = nil
  @assertions_module = find_best_assertions_module
end

Private Class Methods

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

Public Instance Methods

begin_rb_scenario(scenario) click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 92
def begin_rb_scenario(scenario)
  create_world
  extend_world
  connect_world(scenario)
end
build_rb_world_factory(world_modules, proc) click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 112
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
find_best_assertions_module() click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 62
def find_best_assertions_module
  begin
    ::RSpec::Matchers
  rescue NameError
    # RSpec >=1.2.4
    begin
      options = OpenStruct.new(:diff_format => :unified, :context_lines => 3)
      Spec::Expectations.differ = Spec::Expectations::Differs::Default.new(options)
      ::Spec::Matchers
    rescue NameError
      ::Test::Unit::Assertions
    end
  end
end
load_code_file(code_file) click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 121
def load_code_file(code_file)
  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 98
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 106
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 102
def register_rb_transform(regexp, proc)
  add_transform(RbTransform.new(self, regexp, proc))
end
snippet_text(code_keyword, step_name, multiline_arg_class, snippet_type = :regexp) click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 87
def snippet_text(code_keyword, step_name, multiline_arg_class, snippet_type = :regexp)
  snippet_class = typed_snippet_class(snippet_type)
  snippet_class.new(code_keyword, step_name, multiline_arg_class).to_s
end
step_matches(name_to_match, name_to_format) click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 77
def step_matches(name_to_match, name_to_format)
  @step_definitions.map do |step_definition|
    if(arguments = step_definition.arguments_from(name_to_match))
      StepMatch.new(step_definition, name_to_match, name_to_format, arguments)
    else
      nil
    end
  end.compact
end

Protected Instance Methods

begin_scenario(scenario) click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 127
def begin_scenario(scenario)
  begin_rb_scenario(scenario)
end
end_scenario() click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 131
def end_scenario
  @current_world = nil
end

Private Instance Methods

check_nil(o, proc) click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 159
def check_nil(o, proc)
  if o.nil?
    begin
      raise NilWorld.new
    rescue NilWorld => e
      e.backtrace.clear
      e.backtrace.push(proc.backtrace_line("World"))
      raise e
    end
  else
    o
  end
end
connect_world(scenario) click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 154
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 137
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 146
def extend_world
  @current_world.extend(RbWorld)
  @current_world.extend(@assertions_module)
  (@world_modules || []).each do |mod|
    @current_world.extend(mod)
  end
end
typed_snippet_class(type) click to toggle source
# File lib/cucumber/rb_support/rb_language.rb, line 179
def typed_snippet_class(type)
  SNIPPET_TYPES.fetch(type || :regexp)
end