Module: AssertType::AssertMethods
- Defined in:
- lib/assert_type.rb
Instance Method Summary collapse
- #at_assert(truth) ⇒ Object
- #at_assert_equal(expected, actual) ⇒ Object
- #at_assert_type(expected_type, value) ⇒ Object
Instance Method Details
#at_assert(truth) ⇒ Object
12 13 14 15 16 |
# File 'lib/assert_type.rb', line 12 def at_assert truth unless truth raise AssertionError, "Expected truthy but was #{truth.inspect}" end end |
#at_assert_equal(expected, actual) ⇒ Object
18 19 20 21 22 |
# File 'lib/assert_type.rb', line 18 def at_assert_equal expected, actual unless expected == actual raise AssertionError.new expected, actual end end |
#at_assert_type(expected_type, value) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/assert_type.rb', line 24 def at_assert_type expected_type, value if expected_type.is_a? Class unless expected_type === value raise TypeAssertionError.new expected_type.to_s, value end elsif expected_type.is_a? Array unless expected_type.any? {|t| t === value} types = expected_type.join(' or ') raise TypeAssertionError.new types, value end elsif expected_type.is_a? String if node = AssertType::TypeStringParser.parse(expected_type) unless AssertType::TypeValidator.valid?(node, value) raise TypeAssertionError.new expected_type, value end else raise ParseError.new end else raise CallError.new end end |