Class: Smartest::RaiseErrorMatcher
- Defined in:
- lib/smartest/matchers.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(*expected_error) ⇒ RaiseErrorMatcher
constructor
A new instance of RaiseErrorMatcher.
- #matches?(actual) ⇒ Boolean
- #negated_failure_message ⇒ Object
Methods inherited from Matcher
Constructor Details
#initialize(*expected_error) ⇒ RaiseErrorMatcher
Returns a new instance of RaiseErrorMatcher.
528 529 530 531 532 533 534 |
# File 'lib/smartest/matchers.rb', line 528 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
#description ⇒ Object
561 562 563 |
# File 'lib/smartest/matchers.rb', line 561 def description "raise #{expected_description}" end |
#failure_message ⇒ Object
550 551 552 553 554 555 |
# File 'lib/smartest/matchers.rb', line 550 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
536 537 538 539 540 541 542 543 544 545 546 547 548 |
# File 'lib/smartest/matchers.rb', line 536 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
557 558 559 |
# File 'lib/smartest/matchers.rb', line 557 def "expected block not to raise #{expected_description}, but raised #{actual_error_description}" end |