Class: Crspec::Matchers::RaiseErrorMatcher
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- Crspec::Matchers::RaiseErrorMatcher
- Defined in:
- lib/crspec/matchers.rb
Instance Attribute Summary
Attributes inherited from BaseMatcher
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(expected_exception = StandardError, expected_message = nil) ⇒ RaiseErrorMatcher
constructor
A new instance of RaiseErrorMatcher.
- #matches?(block) ⇒ Boolean
Constructor Details
#initialize(expected_exception = StandardError, expected_message = nil) ⇒ RaiseErrorMatcher
Returns a new instance of RaiseErrorMatcher.
110 111 112 113 114 115 |
# File 'lib/crspec/matchers.rb', line 110 def initialize(expected_exception = StandardError, = nil) super(expected_exception) @expected_exception = expected_exception @expected_message = @actual_exception = nil end |
Instance Method Details
#failure_message ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/crspec/matchers.rb', line 129 def if @actual_exception "Expected #{@expected_exception}#{@expected_message ? " with message #{@expected_message.inspect}" : ""}, but got #{@actual_exception.class}: #{@actual_exception..inspect}" else "Expected #{@expected_exception} to be raised, but nothing was raised" end end |
#failure_message_when_negated ⇒ Object
137 138 139 |
# File 'lib/crspec/matchers.rb', line 137 def "Expected no exception, but #{@actual_exception.class} was raised" end |
#matches?(block) ⇒ Boolean
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/crspec/matchers.rb', line 117 def matches?(block) raise ArgumentError, "raise_error matcher requires a block" unless block.respond_to?(:call) begin block.call false rescue Exception => e @actual_exception = e matches_exception?(e) end end |