Class: Matchy::Expectations::RaiseErrorExpectation
- Defined in:
- lib/matchy/built_in/error_expectations.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(expected, test_case) ⇒ RaiseErrorExpectation
constructor
A new instance of RaiseErrorExpectation.
- #matches?(receiver) ⇒ Boolean
- #negative_failure_message ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(expected, test_case) ⇒ RaiseErrorExpectation
Returns a new instance of RaiseErrorExpectation.
4 5 6 7 |
# File 'lib/matchy/built_in/error_expectations.rb', line 4 def initialize(expected, test_case) @error = nil super end |
Instance Method Details
#failure_message ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/matchy/built_in/error_expectations.rb', line 22 def extra = "" if @error extra = "but #{@error.class.name} was raised instead" else extra = "but none was raised" end "Expected #{@receiver.inspect} to raise #{@expected.name}, #{extra}." end |
#matches?(receiver) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/matchy/built_in/error_expectations.rb', line 9 def matches?(receiver) @receiver = receiver begin receiver.call return false rescue StandardError => e @error = e return false unless e.class.ancestors.include?(@expected) return true end end |
#negative_failure_message ⇒ Object
33 34 35 |
# File 'lib/matchy/built_in/error_expectations.rb', line 33 def "Expected #{@receiver.inspect} to not raise #{@expected.name}." end |