Class: RaiseErrorMatcher

Inherits:
Object show all
Defined in:
lib/extensions/rhospec/rhospec.rb,
lib/extensions/mspec/mspec/matchers/raise_error.rb

Instance Method Summary collapse

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, message, &block)
  @exception = exception
  @message = message
  @block = block
end

Instance Method Details

#failure_messageObject



409
410
411
412
413
414
415
416
417
418
419
# File 'lib/extensions/rhospec/rhospec.rb', line 409

def failure_message
  message = ["Expected #{@exception}#{%[ (#{@message})] if @message}"]

  if @actual then
    message << "but got #{@actual.class}#{%[ (#{@actual.message})] if @actual.message}"
  else
    message << "but no exception was raised"
  end

  message
end

#matches?(proc) ⇒ Boolean

Returns:

  • (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.message
    when Regexp then
      return false if @message !~ @actual.message
    end
  end

  @block[@actual] if @block

  return true
end

#negative_failure_messageObject



421
422
423
# File 'lib/extensions/rhospec/rhospec.rb', line 421

def negative_failure_message
  ["Expected to not get #{@exception}#{%[ (#{@message})] if @message}", ""]
end