Class: Cucumber::StepMother
- Defined in:
- lib/gems/cucumber-0.1.15/lib/cucumber/step_mother.rb
Constant Summary collapse
- PENDING =
lambda do |*_| raise Pending end
Instance Method Summary collapse
-
#execute(step) ⇒ Object
TODO - move execute here?.
- #has_step_definition?(step_name) ⇒ Boolean
-
#initialize ⇒ StepMother
constructor
A new instance of StepMother.
- #proc_for(regexp) ⇒ Object
- #regexp_args_proc(step_name) ⇒ Object
- #register_step_proc(key, &proc) ⇒ Object
Constructor Details
#initialize ⇒ StepMother
Returns a new instance of StepMother.
30 31 32 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/step_mother.rb', line 30 def initialize @step_procs = Hash.new(PENDING) end |
Instance Method Details
#execute(step) ⇒ Object
TODO - move execute here?
95 96 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/step_mother.rb', line 95 def execute(step) end |
#has_step_definition?(step_name) ⇒ Boolean
89 90 91 92 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/step_mother.rb', line 89 def has_step_definition?(step_name) _, _, proc = regexp_args_proc(step_name) proc != PENDING end |
#proc_for(regexp) ⇒ Object
85 86 87 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/step_mother.rb', line 85 def proc_for(regexp) @step_procs[regexp] end |
#regexp_args_proc(step_name) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/step_mother.rb', line 63 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 = %{Multiple step definitions match #{step_name.inspect}: #{candidates.map{|regexp, args, proc| proc.to_backtrace_line}.join("\n")} } raise Multiple.new() end end |
#register_step_proc(key, &proc) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/step_mother.rb', line 34 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] = %{Duplicate step definitions: #{first_proc.to_backtrace_line} #{proc.to_backtrace_line} } raise Duplicate.new() end @step_procs[regexp] = proc end |