Class: Wukong::SpecHelpers::UnitTestMatcher
- Inherits:
-
Object
- Object
- Wukong::SpecHelpers::UnitTestMatcher
- Defined in:
- lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#actual_record ⇒ Object
Returns the value of attribute actual_record.
-
#driver ⇒ Object
Returns the value of attribute driver.
-
#expected ⇒ Object
Returns the value of attribute expected.
-
#expected_record ⇒ Object
Returns the value of attribute expected_record.
-
#mismatched_index ⇒ Object
Returns the value of attribute mismatched_index.
-
#reason ⇒ Object
Returns the value of attribute reason.
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(*expected) ⇒ UnitTestMatcher
constructor
A new instance of UnitTestMatcher.
- #matches?(driver) ⇒ Boolean
- #negative_failure_message ⇒ Object
- #records ⇒ Object (also: #record)
Constructor Details
#initialize(*expected) ⇒ UnitTestMatcher
Returns a new instance of UnitTestMatcher.
28 29 30 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 28 def initialize *expected self.expected = expected end |
Instance Attribute Details
#actual_record ⇒ Object
Returns the value of attribute actual_record.
5 6 7 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 5 def actual_record @actual_record end |
#driver ⇒ Object
Returns the value of attribute driver.
5 6 7 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 5 def driver @driver end |
#expected ⇒ Object
Returns the value of attribute expected.
5 6 7 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 5 def expected @expected end |
#expected_record ⇒ Object
Returns the value of attribute expected_record.
5 6 7 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 5 def expected_record @expected_record end |
#mismatched_index ⇒ Object
Returns the value of attribute mismatched_index.
5 6 7 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 5 def mismatched_index @mismatched_index end |
#reason ⇒ Object
Returns the value of attribute reason.
5 6 7 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 5 def reason @reason end |
Instance Method Details
#failure_message ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 32 def if reason == :size "Expected #{expected_size} records, got #{actual_size}:\n\n#{pretty_output}" else "Expected the #{ordinalize(mismatched_index)} record to be#{parse_modifier}\n\n#{expected_record}\n\nbut got\n\n#{pretty_output}" end end |
#matches?(driver) ⇒ Boolean
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 7 def matches?(driver) self.driver = driver driver.run if actual_size != expected_size self.reason = :size return false end return true if just_count? expected.each_with_index do |expectation, index| actual = output[index] if actual != expectation self.reason = :element self.expected_record = expectation self.actual_record = actual self.mismatched_index = index return false end end true end |
#negative_failure_message ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 40 def if reason == :size "Expected to NOT get #{expected_size} records:\n\n#{output}" else "Expected the #{ordinalize(mismatched_index)} record to NOT be#{parse_modifier}\n\n#{pretty_output}" end end |
#records ⇒ Object Also known as: record
48 49 50 51 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb', line 48 def records @just_count = true self # chaining end |