Class: Cucumber::RbSupport::RbStepDefinition

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

Overview

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

Defined Under Namespace

Classes: MissingProc

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rb_language, regexp, proc) ⇒ RbStepDefinition

Returns a new instance of RbStepDefinition.



67
68
69
70
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 67

def initialize(rb_language, regexp, proc)
  @rb_language, @regexp, @proc = rb_language, regexp, proc
  @rb_language.available_step_definition(regexp_source, file_colon_line)
end

Class Method Details

.new(rb_language, pattern, proc_or_sym, options) ⇒ Object

Raises:



27
28
29
30
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 27

def new(rb_language, pattern, proc_or_sym, options)
  raise MissingProc if proc_or_sym.nil?
  super rb_language, parse_pattern(pattern), create_proc(proc_or_sym, options)
end

Instance Method Details

#==(step_definition) ⇒ Object



84
85
86
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 84

def ==(step_definition)
  regexp_source == step_definition.regexp_source
end

#arguments_from(step_name) ⇒ Object



88
89
90
91
92
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 88

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_lineObject



104
105
106
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 104

def backtrace_line
  @proc.backtrace_line(regexp_source)
end

#fileObject



117
118
119
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 117

def file
  @file ||= file_colon_line.split(':')[0]
end

#file_colon_lineObject



108
109
110
111
112
113
114
115
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 108

def file_colon_line
  case @proc
  when Proc
    @proc.file_colon_line
  when Symbol
    ":#{@proc}"
  end
end

#invoke(args) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 94

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_sourceObject



72
73
74
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 72

def regexp_source
  @regexp.inspect
end

#to_hashObject



76
77
78
79
80
81
82
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 76

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