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.
219 220 221 |
# File 'lib/roadforest/test-support/matchers.rb', line 219 def initialize(expected) @expected = expected end |
Instance Method Details
#failure_message_for_should ⇒ Object
244 245 246 247 248 249 |
# File 'lib/roadforest/test-support/matchers.rb', line 244 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
239 240 241 242 |
# File 'lib/roadforest/test-support/matchers.rb', line 239 def matches?(actual) @actual = actual missing.empty? and surplus.empty? end |
#missing ⇒ Object
231 232 233 |
# File 'lib/roadforest/test-support/matchers.rb', line 231 def missing @missing ||= subtract(@expected, @actual) end |
#subtract(one, other) ⇒ Object
223 224 225 226 227 228 229 |
# 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 ⇒ Object
235 236 237 |
# File 'lib/roadforest/test-support/matchers.rb', line 235 def surplus @surplus ||= subtract(@actual, @expected) end |