Class: Matchy::Expectations::ThrowSymbolExpectation
- Defined in:
- lib/matchy/built_in/error_expectations.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(expected, test_case) ⇒ ThrowSymbolExpectation
constructor
A new instance of ThrowSymbolExpectation.
- #matches?(receiver) ⇒ Boolean
- #negative_failure_message ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(expected, test_case) ⇒ ThrowSymbolExpectation
Returns a new instance of ThrowSymbolExpectation.
39 40 41 42 |
# File 'lib/matchy/built_in/error_expectations.rb', line 39 def initialize(expected, test_case) @thrown_symbol = nil super end |
Instance Method Details
#failure_message ⇒ Object
56 57 58 |
# File 'lib/matchy/built_in/error_expectations.rb', line 56 def "Expected #{@receiver.inspect} to throw :#{@expected}, but #{@thrown_symbol ? ':' + @thrown_symbol.to_s + ' was thrown instead' : 'no symbol was thrown'}." end |
#matches?(receiver) ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/matchy/built_in/error_expectations.rb', line 44 def matches?(receiver) @receiver = receiver begin receiver.call rescue NameError => e raise e unless e. =~ /uncaught throw/ @thrown_symbol = e.name.to_sym ensure return @expected == @thrown_symbol end end |
#negative_failure_message ⇒ Object
60 61 62 |
# File 'lib/matchy/built_in/error_expectations.rb', line 60 def "Expected #{@receiver.inspect} to not throw :#{@expected}." end |