Class: Lucid::InterfaceRb::RbStepDefinition
- Defined in:
- lib/lucid/interface_rb/rb_step_definition.rb
Overview
A Ruby test definition holds a Regexp and a Proc, and is created by calling Given
, When
or Then
.
Example:
Given /there are (\d+) lucid tests to run/ 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
- #regexp_source ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(rb_language, regexp, proc) ⇒ RbStepDefinition
Returns a new instance of RbStepDefinition.
65 66 67 68 |
# File 'lib/lucid/interface_rb/rb_step_definition.rb', line 65 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
25 26 27 28 |
# File 'lib/lucid/interface_rb/rb_step_definition.rb', line 25 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
82 83 84 |
# File 'lib/lucid/interface_rb/rb_step_definition.rb', line 82 def ==(step_definition) regexp_source == step_definition.regexp_source end |
#arguments_from(step_name) ⇒ Object
86 87 88 89 90 |
# File 'lib/lucid/interface_rb/rb_step_definition.rb', line 86 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
102 103 104 |
# File 'lib/lucid/interface_rb/rb_step_definition.rb', line 102 def backtrace_line @proc.backtrace_line(regexp_source) end |
#file ⇒ Object
115 116 117 |
# File 'lib/lucid/interface_rb/rb_step_definition.rb', line 115 def file @file ||= file_colon_line.split(':')[0] end |
#file_colon_line ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/lucid/interface_rb/rb_step_definition.rb', line 106 def file_colon_line case @proc when Proc @proc.file_colon_line when Symbol ":#{@proc}" end end |
#invoke(args) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/lucid/interface_rb/rb_step_definition.rb', line 92 def invoke(args) begin args = @rb_language.execute_transforms(args) @rb_language.current_domain.lucid_instance_exec(true, regexp_source, *args, &@proc) rescue Lucid::ArityMismatchError => e e.backtrace.unshift(self.backtrace_line) raise e end end |
#regexp_source ⇒ Object
70 71 72 |
# File 'lib/lucid/interface_rb/rb_step_definition.rb', line 70 def regexp_source @regexp.inspect end |
#to_hash ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/lucid/interface_rb/rb_step_definition.rb', line 74 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 |