class ComplainMatcher

Public Class Methods

new(complaint) click to toggle source
# File lib/mspec/matchers/complain.rb, line 4
def initialize(complaint)
  @complaint = complaint
end

Public Instance Methods

failure_message() click to toggle source
# File lib/mspec/matchers/complain.rb, line 31
def failure_message
  if @complaint.nil?
    ["Expected a warning", "but received none"]
  elsif @complaint.kind_of? Regexp
    ["Expected warning to match:", @complaint.inspect]
  else
    ["Expected warning: #{@complaint.inspect}", "but got: #{@stderr.chomp.inspect}"]
  end
end
matches?(proc) click to toggle source
# File lib/mspec/matchers/complain.rb, line 8
def matches?(proc)
  @saved_err = $stderr
  @stderr = $stderr = IOStub.new
  @verbose = $VERBOSE
  $VERBOSE = false

  proc.call

  unless @complaint.nil?
    case @complaint
    when Regexp
      return false unless $stderr =~ @complaint
    else
      return false unless $stderr == @complaint
    end
  end

  return $stderr.empty? ? false : true
ensure
  $VERBOSE = @verbose
  $stderr = @saved_err
end
negative_failure_message() click to toggle source
# File lib/mspec/matchers/complain.rb, line 41
def negative_failure_message
  if @complaint.nil?
    ["Unexpected warning: ", @stderr.chomp.inspect]
  elsif @complaint.kind_of? Regexp
    ["Expected warning not to match:", @complaint.inspect]
  else
    ["Expected warning: #{@complaint.inspect}", "but got: #{@stderr.chomp.inspect}"]
  end
end