Class: Cucumber::Runtime::SupportCode

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber_priority/support_code_ext.rb

Instance Method Summary collapse

Instance Method Details

#step_match_with_priority(*args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cucumber_priority/support_code_ext.rb', line 5

def step_match_with_priority(*args)
  step_match_without_priority(*args)
rescue Ambiguous => e
  overridable, overriding = e.matches.partition { |match|
    match.step_definition.overridable?
  }
  if overriding.size > 1
    # If we have more than one overriding step definitions,
    # this is an ambiguity error
    raise
  elsif overriding.size == 1
    # If our ambiguity is due to another overridable step,
    # we can use the overriding step
    overriding.first
  elsif overriding.size == 0
    # If we have multiple overridable steps, we use the one
    # with the highest priority.
    overridable.sort_by { |match|
      match.step_definition.priority
    }.last
  end
end