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
Methods inherited from BaseMatcher
Constructor Details
#initialize(expected_exception = StandardError, expected_message = nil) ⇒ RaiseErrorMatcher
Returns a new instance of RaiseErrorMatcher.
190 191 192 193 194 195 |
# File 'lib/crspec/matchers.rb', line 190 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
209 210 211 212 213 214 215 |
# File 'lib/crspec/matchers.rb', line 209 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
217 218 219 |
# File 'lib/crspec/matchers.rb', line 217 def "Expected no exception, but #{@actual_exception.class} was raised" end |
#matches?(block) ⇒ Boolean
197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/crspec/matchers.rb', line 197 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 |