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.
78 79 80 81 82 |
# File 'lib/smartest/matchers.rb', line 78 def initialize(expected_error) @expected_error = expected_error @actual_error = nil @callable = true end |
Instance Method Details
#failure_message ⇒ Object
98 99 100 101 102 103 |
# File 'lib/smartest/matchers.rb', line 98 def return "expected a block to raise #{@expected_error}" unless @callable return "expected block to raise #{@expected_error}, but nothing was raised" unless @actual_error "expected block to raise #{@expected_error}, but raised #{@actual_error.class}: #{@actual_error.}" end |
#matches?(actual) ⇒ Boolean
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/smartest/matchers.rb', line 84 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 error.is_a?(@expected_error) end |
#negated_failure_message ⇒ Object
105 106 107 |
# File 'lib/smartest/matchers.rb', line 105 def "expected block not to raise #{@expected_error}, but raised #{@actual_error.class}: #{@actual_error.}" end |