Parent

Files

Class/Module Index [+]

Quicksearch

Cucumber::RbSupport::RbStepDefinition

A Ruby Step Definition holds a Regexp and a Proc, and is created by calling Given, When or Then in the step_definitions ruby files. See also RbDsl.

Example:

Given /I have (\d+) cucumbers in my belly/ do
  # some code here
end

Public Class Methods

new(rb_language, regexp, proc) click to toggle source
# File lib/cucumber/rb_support/rb_step_definition.rb, line 26
def initialize(rb_language, regexp, proc)
  raise MissingProc if proc.nil?
  if String === regexp
    p = Regexp.escape(regexp)
    p = p.gsub(/\\\$\w+/, '(.*)') # Replace $var with (.*)
    regexp = Regexp.new("^#{p}$") 
  end
  @rb_language, @regexp, @proc = rb_language, regexp, proc
  @rb_language.available_step_definition(regexp_source, file_colon_line)
end

Public Instance Methods

==(step_definition) click to toggle source
# File lib/cucumber/rb_support/rb_step_definition.rb, line 49
def ==(step_definition)
  regexp_source == step_definition.regexp_source
end
arguments_from(step_name) click to toggle source
# File lib/cucumber/rb_support/rb_step_definition.rb, line 53
def arguments_from(step_name)
  args = RegexpArgumentMatcher.arguments_from(@regexp, step_name)
  @rb_language.invoked_step_definition(regexp_source, file_colon_line) if args
  args
end
backtrace_line() click to toggle source
# File lib/cucumber/rb_support/rb_step_definition.rb, line 69
def backtrace_line
  @proc.backtrace_line(regexp_source)
end
file() click to toggle source
# File lib/cucumber/rb_support/rb_step_definition.rb, line 77
def file
  @file ||= file_colon_line.split(':')[0]
end
file_colon_line() click to toggle source
# File lib/cucumber/rb_support/rb_step_definition.rb, line 73
def file_colon_line
  @proc.file_colon_line
end
invoke(args) click to toggle source
# File lib/cucumber/rb_support/rb_step_definition.rb, line 59
def invoke(args)
  begin
    args = @rb_language.execute_transforms(args)
    @rb_language.current_world.cucumber_instance_exec(true, regexp_source, *args, &@proc)
  rescue Cucumber::ArityMismatchError => e
    e.backtrace.unshift(self.backtrace_line)
    raise e
  end
end
regexp_source() click to toggle source
# File lib/cucumber/rb_support/rb_step_definition.rb, line 37
def regexp_source
  @regexp.inspect
end
to_hash() click to toggle source
# File lib/cucumber/rb_support/rb_step_definition.rb, line 41
def to_hash
  flags = ''
  flags += 'm' if (@regexp.options & Regexp::MULTILINE) != 0
  flags += 'i' if (@regexp.options & Regexp::IGNORECASE) != 0
  flags += 'x' if (@regexp.options & Regexp::EXTENDED) != 0
  {'source' => @regexp.source, 'flags' => flags}
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.