Module: Trailblazer::Test::Assertion::AssertExposes

Defined in:
lib/trailblazer/test/assertion/assert_exposes.rb

Defined Under Namespace

Modules: Assert

Instance Method Summary collapse

Instance Method Details

#_assert_exposes_for(asserted, expected, **options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/trailblazer/test/assertion/assert_exposes.rb', line 21

def _assert_exposes_for(asserted, expected, **options)
  passed, matches, last_failed = Assert.assert_attributes(asserted, expected, **options) do |_matches, last_failed|
    name, expected_value, actual_value, _passed, is_eq, error_msg = last_failed

    is_eq ? assert_equal(expected_value, actual_value, error_msg) : assert(expected_value, error_msg)

    return false
  end

  return true
end

#assert_exposes(asserted, expected = nil, reader: nil, **options) ⇒ Object

Test if all ‘tuples` values on `asserted` match the expected values. TODO: test err msgs!

Parameters:

  • asserted

    Object Object that exposes attributes to test

  • tuples

    Hash Key/value attribute pairs to test

  • options

    Hash Default :reader is ‘asserted.name`,



10
11
12
13
14
# File 'lib/trailblazer/test/assertion/assert_exposes.rb', line 10

def assert_exposes(asserted, expected=nil, reader: nil, **options)
  expected = options.any? ? options : expected # allow passing {expected} as kwargs, too.

  _assert_exposes_for(asserted, expected, reader: reader)
end