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.
151 152 153 154 155 |
# File 'lib/smartest/matchers.rb', line 151 def initialize(expected_error) @expected_error = expected_error @actual_error = nil @callable = true end |
Instance Method Details
#failure_message ⇒ Object
171 172 173 174 175 176 |
# File 'lib/smartest/matchers.rb', line 171 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
157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/smartest/matchers.rb', line 157 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
178 179 180 |
# File 'lib/smartest/matchers.rb', line 178 def "expected block not to raise #{@expected_error}, but raised #{@actual_error.class}: #{@actual_error.}" end |