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
Class Method Summary collapse
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
- #location ⇒ Object
- #regexp_source ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(rb_language, regexp, proc) ⇒ RbStepDefinition
Returns a new instance of RbStepDefinition.
72 73 74 75 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 72 def initialize(rb_language, regexp, proc) @rb_language, @regexp, @proc = rb_language, regexp, proc @rb_language.available_step_definition(regexp_source, location) end |
Class Method Details
.new(rb_language, pattern, proc_or_sym, options) ⇒ Object
26 27 28 29 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 26 def new(rb_language, pattern, proc_or_sym, ) raise MissingProc if proc_or_sym.nil? super rb_language, parse_pattern(pattern), create_proc(proc_or_sym, ) end |
Instance Method Details
#==(step_definition) ⇒ Object
89 90 91 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 89 def ==(step_definition) regexp_source == step_definition.regexp_source end |
#arguments_from(step_name) ⇒ Object
93 94 95 96 97 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 93 def arguments_from(step_name) args = StepArgument.arguments_from(@regexp, step_name) @rb_language.invoked_step_definition(regexp_source, location) if args args end |
#backtrace_line ⇒ Object
109 110 111 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 109 def backtrace_line "#{location.to_s}:in `#{regexp_source}'" end |
#file ⇒ Object
126 127 128 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 126 def file @file ||= location.file end |
#file_colon_line ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 113 def file_colon_line case @proc when Proc location.to_s when Symbol ":#{@proc}" end end |
#invoke(args) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 99 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 |
#location ⇒ Object
122 123 124 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 122 def location @location ||= Cucumber::Core::Ast::Location.from_source_location(*@proc.source_location) end |
#regexp_source ⇒ Object
77 78 79 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 77 def regexp_source @regexp.inspect end |
#to_hash ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/cucumber/rb_support/rb_step_definition.rb', line 81 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 |