Class: CucumberPriority::Resolver

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

Class Method Summary collapse

Class Method Details

.resolve_ambiguity_through_priority(e) ⇒ Object



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

def self.resolve_ambiguity_through_priority(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 e
  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
    }.first
  end
end