Class: Spec::Matchers::RaiseError
- Defined in:
- lib/spec/matchers/raise_error.rb
Overview
:nodoc:
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(exception = Exception, message = nil) ⇒ RaiseError
constructor
A new instance of RaiseError.
- #matches?(proc) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(exception = Exception, message = nil) ⇒ RaiseError
Returns a new instance of RaiseError.
5 6 7 8 |
# File 'lib/spec/matchers/raise_error.rb', line 5 def initialize(exception=Exception, =nil) @expected_error = exception @expected_message = end |
Instance Method Details
#description ⇒ Object
49 50 51 |
# File 'lib/spec/matchers/raise_error.rb', line 49 def description "raise #{expected_error}" end |
#failure_message ⇒ Object
41 42 43 |
# File 'lib/spec/matchers/raise_error.rb', line 41 def return "expected #{expected_error}#{actual_error}" if @raised_other || !@raised_expected_error end |
#matches?(proc) ⇒ Boolean
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/spec/matchers/raise_error.rb', line 10 def matches?(proc) @raised_expected_error = false @raised_other = false begin proc.call rescue @expected_error => @actual_error if @expected_message.nil? @raised_expected_error = true else case @expected_message when Regexp if @expected_message =~ @actual_error. @raised_expected_error = true else @raised_other = true end else if @actual_error. == @expected_message @raised_expected_error = true else @raised_other = true end end end rescue => @actual_error @raised_other = true ensure return @raised_expected_error end end |
#negative_failure_message ⇒ Object
45 46 47 |
# File 'lib/spec/matchers/raise_error.rb', line 45 def "expected no #{expected_error}#{actual_error}" end |