class Cucumber::StepMatch
:nodoc:
def activate(test_step)
def activate(test_step) test_step.with_action(@step_definition.location) do invoke(MultilineArgument.from_core(test_step.source.last.multiline_arg)) end end
def args
def args @step_arguments.map{|g| g.val } end
def backtrace_line
def backtrace_line "#{file_colon_line}:in `#{@step_definition.regexp_source}'" end
def deep_clone_args
def deep_clone_args Marshal.load( Marshal.dump( args ) ) end
def file_colon_line
def file_colon_line location.to_s end
def format_args(format = lambda{|a| a}, &proc)
lambda { |param| "[#{param}]" }
argument, for example:
If it is a Proc, it should take one argument and return the formatted
'%s'
Kernel#sprinf, for example:
If it is a String it should be a format string according to
The +format+ can either be a String or a Proc.
is usually called from visitors, which render output.
Formats the matched arguments of the associated Step. This method
def format_args(format = lambda{|a| a}, &proc) @name_to_report || replace_arguments(@name_to_match, @step_arguments, format, &proc) end
def initialize(step_definition, name_to_match, name_to_report, step_arguments)
reported, unless it's is, in which case +name_to_report+ is used instead.
Creates a new StepMatch. The +name_to_report+ argument is what's
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
def inspect #:nodoc:
def inspect #:nodoc: sprintf("#<%s:0x%x>", self.class, self.object_id) end
def invoke(multiline_arg)
def invoke(multiline_arg) all_args = deep_clone_args multiline_arg.append_to(all_args) @step_definition.invoke(all_args) end
def location
def location @step_definition.location end
def name
def name @name_to_report end
def replace_arguments(string, step_arguments, format, &proc)
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
def text_length
def text_length @step_definition.regexp_source.unpack('U*').length end