Class: Cucumber::RbSupport::RbStepDefinition
- 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
Instance Method Summary collapse
- #==(step_definition) ⇒ Object
- #arguments_from(step_name) ⇒ Object
- #backtrace_line ⇒ Object
- #file ⇒ Object
- #file_colon_line ⇒ Object
-
#initialize(rb_language, regexp, proc) ⇒ RbStepDefinition
constructor
A new instance of RbStepDefinition.
- #invoke(args) ⇒ Object
- #regexp_source ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(rb_language, regexp, proc) ⇒ RbStepDefinition
Returns a new instance of RbStepDefinition.
26 27 28 29 30 31 32 33 34 35 |
# 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 |
Instance Method Details
#==(step_definition) ⇒ Object
49 50 51 |
# 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) ⇒ Object
53 54 55 56 57 |
# 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 ⇒ Object
69 70 71 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 69 def backtrace_line @proc.backtrace_line(regexp_source) end |
#file ⇒ Object
77 78 79 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 77 def file @file ||= file_colon_line.split(':')[0] end |
#file_colon_line ⇒ Object
73 74 75 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 73 def file_colon_line @proc.file_colon_line end |
#invoke(args) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# 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 ⇒ Object
37 38 39 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 37 def regexp_source @regexp.inspect end |
#to_hash ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 41 def to_hash flags = '' flags += 'm' if (@regexp. & Regexp::MULTILINE) != 0 flags += 'i' if (@regexp. & Regexp::IGNORECASE) != 0 flags += 'x' if (@regexp. & Regexp::EXTENDED) != 0 {'source' => @regexp.source, 'flags' => flags} end |