Class: Cucumber::StepMatch
Overview
:nodoc:
Instance Attribute Summary collapse
-
#step_arguments ⇒ Object
readonly
Returns the value of attribute step_arguments.
-
#step_definition ⇒ Object
readonly
Returns the value of attribute step_definition.
Instance Method Summary collapse
- #activate(test_step) ⇒ Object
- #args ⇒ Object
- #backtrace_line ⇒ Object
- #file_colon_line ⇒ Object
-
#format_args(format = lambda{|a| a}, &proc) ⇒ Object
Formats the matched arguments of the associated Step.
-
#initialize(step_definition, name_to_match, name_to_report, step_arguments) ⇒ StepMatch
constructor
Creates a new StepMatch.
-
#inspect ⇒ Object
:nodoc:.
- #invoke(multiline_arg) ⇒ Object
- #name ⇒ Object
- #replace_arguments(string, step_arguments, format, &proc) ⇒ Object
- #text_length ⇒ Object
Constructor Details
#initialize(step_definition, name_to_match, name_to_report, step_arguments) ⇒ StepMatch
Creates a new StepMatch. The name_to_report
argument is what’s reported, unless it’s is, in which case name_to_report
is used instead.
10 11 12 13 14 |
# File 'lib/cucumber/step_match.rb', line 10 def initialize(step_definition, name_to_match, name_to_report, step_arguments) raise "name_to_match can't be nil" if name_to_match.nil? raise "step_arguments can't be nil (but it can be an empty array)" if step_arguments.nil? @step_definition, @name_to_match, @name_to_report, @step_arguments = step_definition, name_to_match, name_to_report, step_arguments end |
Instance Attribute Details
#step_arguments ⇒ Object (readonly)
Returns the value of attribute step_arguments.
5 6 7 |
# File 'lib/cucumber/step_match.rb', line 5 def step_arguments @step_arguments end |
#step_definition ⇒ Object (readonly)
Returns the value of attribute step_definition.
5 6 7 |
# File 'lib/cucumber/step_match.rb', line 5 def step_definition @step_definition end |
Instance Method Details
#activate(test_step) ⇒ Object
24 25 26 27 28 |
# File 'lib/cucumber/step_match.rb', line 24 def activate(test_step) test_step.with_action do invoke(MultilineArgument.from_core(test_step.source.last.multiline_arg)) end end |
#args ⇒ Object
16 17 18 |
# File 'lib/cucumber/step_match.rb', line 16 def args @step_arguments.map{|g| g.val } end |
#backtrace_line ⇒ Object
59 60 61 |
# File 'lib/cucumber/step_match.rb', line 59 def backtrace_line "#{file_colon_line}:in `#{@step_definition.regexp_source}'" end |
#file_colon_line ⇒ Object
55 56 57 |
# File 'lib/cucumber/step_match.rb', line 55 def file_colon_line @step_definition.file_colon_line end |
#format_args(format = lambda{|a| a}, &proc) ⇒ Object
Formats the matched arguments of the associated Step. This method is usually called from visitors, which render output.
The format
can either be a String or a Proc.
If it is a String it should be a format string according to Kernel#sprinf
, for example:
'<span class="param">%s</span></tt>'
If it is a Proc, it should take one argument and return the formatted argument, for example:
lambda { |param| "[#{param}]" }
51 52 53 |
# File 'lib/cucumber/step_match.rb', line 51 def format_args(format = lambda{|a| a}, &proc) @name_to_report || replace_arguments(@name_to_match, @step_arguments, format, &proc) end |
#inspect ⇒ Object
:nodoc:
88 89 90 |
# File 'lib/cucumber/step_match.rb', line 88 def inspect #:nodoc: sprintf("#<%s:0x%x>", self.class, self.object_id) end |
#invoke(multiline_arg) ⇒ Object
30 31 32 33 34 |
# File 'lib/cucumber/step_match.rb', line 30 def invoke(multiline_arg) all_args = deep_clone_args multiline_arg.append_to(all_args) @step_definition.invoke(all_args) end |
#name ⇒ Object
20 21 22 |
# File 'lib/cucumber/step_match.rb', line 20 def name @name_to_report end |
#replace_arguments(string, step_arguments, format, &proc) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cucumber/step_match.rb', line 67 def replace_arguments(string, step_arguments, format, &proc) s = string.dup offset = past_offset = 0 step_arguments.each do |step_argument| next if step_argument.offset.nil? || step_argument.offset < past_offset replacement = if block_given? proc.call(step_argument.val) elsif Proc === format format.call(step_argument.val) else format % step_argument.val end s[step_argument.offset + offset, step_argument.val.length] = replacement offset += replacement.unpack('U*').length - step_argument.val.unpack('U*').length past_offset = step_argument.offset + step_argument.val.length end s end |
#text_length ⇒ Object
63 64 65 |
# File 'lib/cucumber/step_match.rb', line 63 def text_length @step_definition.regexp_source.unpack('U*').length end |