Class: RaiseErrorMatcher
- Defined in:
- lib/extensions/rhospec/rhospec.rb,
lib/extensions/mspec/mspec/matchers/raise_error.rb
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.
383 384 385 386 387 |
# File 'lib/extensions/rhospec/rhospec.rb', line 383 def initialize(exception, , &block) @exception = exception @message = @block = block end |
Instance Method Details
#failure_message ⇒ Object
409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/extensions/rhospec/rhospec.rb', line 409 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
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/extensions/rhospec/rhospec.rb', line 389 def matches?(proc) proc.call return false rescue Exception => err @actual = err 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
421 422 423 |
# File 'lib/extensions/rhospec/rhospec.rb', line 421 def ["Expected to not get #{@exception}#{%[ (#{@message})] if @message}", ""] end |