Class: Cucumber::RbSupport::RbStepDefinition
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
end
Defined Under Namespace
Classes: MissingProc
Instance Method Summary
collapse
#backtrace_line, #step_match, #text_length
Constructor Details
#initialize(rb_language, regexp, proc) ⇒ RbStepDefinition
Returns a new instance of RbStepDefinition.
27
28
29
30
31
32
33
34
|
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 27
def initialize(rb_language, regexp, proc)
raise MissingProc if proc.nil?
if String === regexp
p = regexp.gsub(/\$\w+/, '(.*)') regexp = Regexp.new("^#{p}$")
end
@rb_language, @regexp, @proc = rb_language, regexp, proc
end
|
Instance Method Details
#==(step_definition) ⇒ Object
40
41
42
|
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 40
def ==(step_definition)
regexp_source == step_definition.regexp_source
end
|
#arguments_from(step_name) ⇒ Object
44
45
46
47
48
|
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 44
def arguments_from(step_name)
args = RegexpArgumentMatcher.arguments_from(@regexp, step_name)
@matched = true if args
args
end
|
69
70
71
|
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 69
def file
@file ||= file_colon_line.split(':')[0]
end
|
#file_colon_line ⇒ Object
65
66
67
|
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 65
def file_colon_line
@proc.file_colon_line
end
|
#invoke(args) ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 50
def invoke(args)
args = args.map{|arg| Ast::PyString === arg ? arg.to_s : arg}
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
|
#matched? ⇒ Boolean
61
62
63
|
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 61
def matched?
@matched
end
|
#regexp_source ⇒ Object
36
37
38
|
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 36
def regexp_source
@regexp.inspect
end
|