class Cucumber::RbSupport::RbLanguage

The Ruby implementation of the programming language API.

def begin_rb_scenario(scenario)

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

def begin_scenario(scenario)

def begin_scenario(scenario)
  begin_rb_scenario(scenario)
end

def build_rb_world_factory(world_modules, proc)

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

def check_nil(o, proc)

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

def connect_world(scenario)

def connect_world(scenario)
  @current_world.__cucumber_step_mother = @step_mother
  @current_world.__natural_language = scenario.language
end

def create_world

def create_world
  if(@world_proc)
    @current_world = @world_proc.call
    check_nil(@current_world, @world_proc)
  else
    @current_world = Object.new
  end
end

def enable_rspec_expectations_if_available

def enable_rspec_expectations_if_available
  begin
    # RSpec >=2.0
    require 'rspec/expectations'
    @rspec_matchers = ::RSpec::Matchers
  rescue LoadError => try_rspec_1_2_4_or_higher
    begin
      require 'spec/expectations'
      require 'spec/runner/differs/default'
      require 'ostruct'
      options = OpenStruct.new(:diff_format => :unified, :context_lines => 3)
      Spec::Expectations.differ = Spec::Expectations::Differs::Default.new(options)
      @rspec_matchers = ::Spec::Matchers
    rescue LoadError => give_up
      @rspec_matchers = Module.new{}
    end
  end
end

def end_scenario

def end_scenario
  @current_world = nil
end

def extend_world

def extend_world
  @current_world.extend(RbWorld)
  @current_world.extend(@rspec_matchers)
  (@world_modules || []).each do |mod|
    @current_world.extend(mod)
  end
end

def initialize(step_mother)

def initialize(step_mother)
  @step_mother = step_mother
  @step_definitions = []
  RbDsl.rb_language = self
  @world_proc = @world_modules = nil
  enable_rspec_expectations_if_available
end

def load_code_file(code_file)

def load_code_file(code_file)
  require 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

def register_rb_hook(phase, tag_expressions, proc)

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

def register_rb_step_definition(regexp, proc)

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

def register_rb_transform(regexp, proc)

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

def snippet_text(step_keyword, step_name, multiline_arg_class)

def snippet_text(step_keyword, step_name, multiline_arg_class)
  snippet_pattern = Regexp.escape(step_name).gsub('\ ', ' ').gsub('/', '\/')
  arg_count = 0
  ARGUMENT_PATTERNS.each do |pattern|
    snippet_pattern = snippet_pattern.gsub(Regexp.new(pattern), pattern)
    arg_count += snippet_pattern.scan(pattern).length
  end
  block_args = (0...arg_count).map {|n| "arg#{n+1}"}
  block_args << multiline_arg_class.default_arg_name unless multiline_arg_class.nil?
  block_arg_string = block_args.empty? ? "" : " |#{block_args.join(", ")}|"
  multiline_class_comment = ""
  if(multiline_arg_class == Ast::Table)
    multiline_class_comment = "# #{multiline_arg_class.default_arg_name} is a #{multiline_arg_class.to_s}\n  "
  end
  "#{Gherkin::I18n.code_keyword_for(step_keyword)} /^#{snippet_pattern}$/ do#{block_arg_string}\n  #{multiline_class_comment}pending # express the regexp above with the code you wish you had\nend"
end

def step_definitions_for(rb_file)

with --require).
Gets called for each file under features (or whatever is overridden
def step_definitions_for(rb_file)
  begin
    require rb_file # This will cause self.add_step_definition and self.add_hook to be called from RbDsl
    step_definitions
  rescue LoadError => e
    e.message << "\nFailed to load #{code_file}"
    raise e
  ensure
    @step_definitions = nil
  end
end

def step_matches(name_to_match, name_to_format)

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