Module: Turnip::Execute

Included in:
RSpec::Execute
Defined in:
lib/turnip/execute.rb

Instance Method Summary collapse

Instance Method Details

#step(description, *extra_args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/turnip/execute.rb', line 3

def step(description, *extra_args)
  extra_args.concat(description.extra_args) if description.respond_to?(:extra_args)

  matches = methods.map do |method|
    next unless method.to_s.start_with?("match: ")
    send(method.to_s, description.to_s)
  end.compact

  if matches.length == 0
    raise Turnip::Pending, description
  end

  if matches.length > 1
    msg = ['Ambiguous step definitions'].concat(matches.map(&:trace)).join("\r\n")
    raise Turnip::Ambiguous, msg
  end

  send(matches.first.method_name, *(matches.first.params + extra_args))
end