aboutsummaryrefslogtreecommitdiffstats
path: root/spec/matchers/disambiguate_attributes.rb
blob: bc4a5215d4c9df8f64114599cf05190c7b2f3fce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module DisambiguateAttributesMatcher
  class DisambiguateAttributes
    def initialize(attributes)
      @attributes = attributes
    end

    def matches?(actual)
      @actual = actual
      attribute1, attribute2 = @attributes
      @actual[attribute1].descends_from?(attribute1) &&
        !@actual[attribute1].descends_from?(attribute2) &&
        @actual[attribute2].descends_from?(attribute2)
    end

    def failure_message
      ""
      # "expected #{@actual} to disambiguate its attributes"
    end

    def negative_failure_message
      "expected #{@actual} to not disambiguate its attributes"
    end
  end

  def disambiguate_attributes(*attributes)
    DisambiguateAttributes.new(attributes)
  end
end