class RoadForest::Testing::ListEquivalence

Public Class Methods

new(expected) click to toggle source
# File lib/roadforest/test-support/matchers.rb, line 219
def initialize(expected)
  @expected = expected
end

Public Instance Methods

failure_message_for_should() click to toggle source
# File lib/roadforest/test-support/matchers.rb, line 244
def failure_message_for_should
  "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) click to toggle source
# File lib/roadforest/test-support/matchers.rb, line 239
def matches?(actual)
  @actual = actual
  missing.empty? and surplus.empty?
end
missing() click to toggle source
# File lib/roadforest/test-support/matchers.rb, line 231
def missing
  @missing ||= subtract(@expected, @actual)
end
subtract(one, other) click to toggle source
# File lib/roadforest/test-support/matchers.rb, line 223
def subtract(one, other)
  one.find_all do |expected_stmt|
    not other.any? do |actual_stmt|
      actual_stmt.eql? expected_stmt
    end
  end
end
surplus() click to toggle source
# File lib/roadforest/test-support/matchers.rb, line 235
def surplus
  @surplus ||= subtract(@actual, @expected)
end