class CucumberPriority::Resolver

Public Class Methods

resolve_ambiguity_through_priority(e) click to toggle source
# 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