Class: RoadForest::Testing::ListEquivalence
- Inherits:
-
Object
- Object
- RoadForest::Testing::ListEquivalence
- Defined in:
- lib/roadforest/test-support/matchers.rb
Instance Method Summary collapse
- #failure_message_for_should ⇒ Object
-
#initialize(expected) ⇒ ListEquivalence
constructor
A new instance of ListEquivalence.
- #matches?(actual) ⇒ Boolean
- #missing ⇒ Object
- #subtract(one, other) ⇒ Object
- #surplus ⇒ Object
Constructor Details
#initialize(expected) ⇒ ListEquivalence
Returns a new instance of ListEquivalence.
31 32 33 |
# File 'lib/roadforest/test-support/matchers.rb', line 31 def initialize(expected) @expected = expected end |
Instance Method Details
#failure_message_for_should ⇒ Object
57 58 59 60 61 62 |
# File 'lib/roadforest/test-support/matchers.rb', line 57 def "expected [\n #{@actual.map(&:to_s).join("\n ")}\n] " + "to have the same elements as [\n #{@expected.map(&:to_s).join("\n ")}\n]\n\n" + "missing: [\n #{missing.map(&:to_s).join("\n ")}\n]\n" + "surplus: [\n #{surplus.map(&:to_s).join("\n ")}]" end |
#matches?(actual) ⇒ Boolean
52 53 54 55 |
# File 'lib/roadforest/test-support/matchers.rb', line 52 def matches?(actual) @actual = actual missing.empty? and surplus.empty? end |
#missing ⇒ Object
44 45 46 |
# File 'lib/roadforest/test-support/matchers.rb', line 44 def missing @missing ||= subtract(@expected, @actual) end |
#subtract(one, other) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/roadforest/test-support/matchers.rb', line 35 def subtract(one, other) sorted = one.sort_by{|stmt| stmt.to_a} one.find_all do |expected_stmt| not other.any? do |actual_stmt| actual_stmt.eql? expected_stmt end end end |
#surplus ⇒ Object
48 49 50 |
# File 'lib/roadforest/test-support/matchers.rb', line 48 def surplus @surplus ||= subtract(@actual, @expected) end |