class Cucumber::StepMother
def execute(step)
def execute(step) end
def has_step_definition?(step_name)
def has_step_definition?(step_name) _, _, proc = regexp_args_proc(step_name) proc != PENDING end
def initialize
def initialize @step_procs = Hash.new(PENDING) end
def proc_for(regexp)
def proc_for(regexp) @step_procs[regexp] end
def regexp_args_proc(step_name)
def regexp_args_proc(step_name) candidates = @step_procs.map do |regexp, proc| if step_name =~ regexp [regexp, $~.captures, proc] end end.compact case(candidates.length) when 0 [nil, [], PENDING] when 1 candidates[0] else message = %{Multiple step definitions match #{step_name.inspect}: ndidates.map{|regexp, args, proc| proc.to_backtrace_line}.join("\n")} raise Multiple.new(message) end end
def register_step_proc(key, &proc)
def register_step_proc(key, &proc) raise MissingProc if proc.nil? regexp = case(key) when String # Replace the $foo and $bar style parameters pattern = key.gsub(/\$\w+/, '(.*)') Regexp.new("^#{pattern}$") when Regexp key else raise "Step patterns must be Regexp or String, but was: #{key.inspect}" end proc.extend(CoreExt::CallIn) proc.name = key.inspect if @step_procs.has_key?(regexp) first_proc = @step_procs[regexp] message = %{Duplicate step definitions: rst_proc.to_backtrace_line} oc.to_backtrace_line} raise Duplicate.new(message) end @step_procs[regexp] = proc end