Module: Trailblazer::Test::Assertion::AssertExposes::Assert
- Defined in:
- lib/trailblazer/test/assertion/assert_exposes.rb
Class Method Summary collapse
-
.assert_attributes(asserted, expected, reader: false) {|matches, last_failed| ... } ⇒ Object
Yields block if tuples don’t match/failed.
-
.match_tuples(asserted, expected, reader:) ⇒ Object
Test if all properties match using our own #test_equal.
- .test_equal(expected, actual) ⇒ Object
- .test_true(expected, actual) ⇒ Object
Class Method Details
.assert_attributes(asserted, expected, reader: false) {|matches, last_failed| ... } ⇒ Object
Yields block if tuples don’t match/failed.
37 38 39 40 41 42 43 |
# File 'lib/trailblazer/test/assertion/assert_exposes.rb', line 37 def assert_attributes(asserted, expected, reader: false, &block) passed, matches, last_failed = match_tuples(asserted, expected, reader: reader) yield matches, last_failed unless passed return passed, matches, last_failed end |
.match_tuples(asserted, expected, reader:) ⇒ Object
Test if all properties match using our own #test_equal.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/trailblazer/test/assertion/assert_exposes.rb', line 47 def match_tuples(asserted, expected, reader:) passed = true # goes {false} if one or more attributes didn't match. matches = expected.collect do |k, v| actual = Test::Assertion.actual(asserted, reader, k) expected, is_eq = Test::Assertion.expected(asserted, v, actual) is_eq ? [k, expected, actual, passed &= test_equal(expected, actual), is_eq, "Property [#{k}] mismatch"] : [k, expected, actual, passed &= test_true(expected, actual), is_eq, "Actual: #{actual.inspect}."] end [passed, matches, matches.find { |k, v, actual, passed, *| !passed }] end |
.test_equal(expected, actual) ⇒ Object
62 63 64 |
# File 'lib/trailblazer/test/assertion/assert_exposes.rb', line 62 def test_equal(expected, actual) expected == actual end |
.test_true(expected, actual) ⇒ Object
66 67 68 |
# File 'lib/trailblazer/test/assertion/assert_exposes.rb', line 66 def test_true(expected, actual) !! expected end |