Class: RaiseErrorMatcher
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(exception, message, &block) ⇒ RaiseErrorMatcher
constructor
A new instance of RaiseErrorMatcher.
- #matches?(proc) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(exception, message, &block) ⇒ RaiseErrorMatcher
Returns a new instance of RaiseErrorMatcher.
2 3 4 5 6 |
# File 'lib/mspec/matchers/raise_error.rb', line 2 def initialize(exception, , &block) @exception = exception @message = @block = block end |
Instance Method Details
#failure_message ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mspec/matchers/raise_error.rb', line 27 def = ["Expected #{@exception}#{%[ (#{@message})] if @message}"] if @actual then << "but got #{@actual.class}#{%[ (#{@actual.})] if @actual.}" else << "but no exception was raised" end end |
#matches?(proc) ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mspec/matchers/raise_error.rb', line 8 def matches?(proc) proc.call return false rescue Exception => @actual return false unless @exception === @actual if @message then case @message when String then return false if @message != @actual. when Regexp then return false if @message !~ @actual. end end @block[@actual] if @block return true end |
#negative_failure_message ⇒ Object
39 40 41 |
# File 'lib/mspec/matchers/raise_error.rb', line 39 def ["Expected to not get #{@exception}#{%[ (#{@message})] if @message}", ""] end |