Class: Smartest::RaiseErrorMatcher
- Inherits:
-
Object
- Object
- Smartest::RaiseErrorMatcher
- Defined in:
- lib/smartest/matchers.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(*expected_error) ⇒ RaiseErrorMatcher
constructor
A new instance of RaiseErrorMatcher.
- #matches?(actual) ⇒ Boolean
- #negated_failure_message ⇒ Object
Constructor Details
#initialize(*expected_error) ⇒ RaiseErrorMatcher
Returns a new instance of RaiseErrorMatcher.
373 374 375 376 377 378 379 |
# File 'lib/smartest/matchers.rb', line 373 def initialize(*expected_error) @expected_type = expected_type_for(expected_error) @expected_error_class = expected_error.find { |item| error_class?(item) } @expected_message_regexp = expected_error.find { |item| item.is_a?(Regexp) } @actual_error = nil @callable = true end |
Instance Method Details
#failure_message ⇒ Object
395 396 397 398 399 400 |
# File 'lib/smartest/matchers.rb', line 395 def return "expected a block to raise #{expected_description}" unless @callable return "expected block to raise #{expected_description}, but nothing was raised" unless @actual_error "expected block to raise #{expected_description}, but raised #{actual_error_description}" end |
#matches?(actual) ⇒ Boolean
381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/smartest/matchers.rb', line 381 def matches?(actual) @actual_error = nil @callable = actual.respond_to?(:call) return false unless @callable actual.call false rescue Exception => error raise if Smartest.fatal_exception?(error) @actual_error = error expected_error_matches?(error) end |
#negated_failure_message ⇒ Object
402 403 404 |
# File 'lib/smartest/matchers.rb', line 402 def "expected block not to raise #{expected_description}, but raised #{actual_error_description}" end |