Class: Spec::Matchers::RaiseError
- Defined in:
- lib/spec/matchers/raise_error.rb
Overview
:nodoc:
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(error_or_message = Exception, message = nil) ⇒ RaiseError
constructor
A new instance of RaiseError.
- #matches?(proc) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(error_or_message = Exception, message = nil) ⇒ RaiseError
Returns a new instance of RaiseError.
5 6 7 8 9 10 11 12 13 |
# File 'lib/spec/matchers/raise_error.rb', line 5 def initialize(=Exception, =nil) if String === @expected_error = Exception @expected_message = else @expected_error = @expected_message = end end |
Instance Method Details
#description ⇒ Object
54 55 56 |
# File 'lib/spec/matchers/raise_error.rb', line 54 def description "raise #{expected_error}" end |
#failure_message ⇒ Object
46 47 48 |
# File 'lib/spec/matchers/raise_error.rb', line 46 def return "expected #{expected_error}#{actual_error}" if @raised_other || !@raised_expected_error end |
#matches?(proc) ⇒ Boolean
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 40 41 42 43 44 |
# File 'lib/spec/matchers/raise_error.rb', line 15 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 @expected_message == @actual_error. @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
50 51 52 |
# File 'lib/spec/matchers/raise_error.rb', line 50 def "expected no #{expected_error}#{actual_error}" end |