diff options
Diffstat (limited to 'spec/mspec/lib/mspec/matchers/complain.rb')
-rw-r--r-- | spec/mspec/lib/mspec/matchers/complain.rb | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/spec/mspec/lib/mspec/matchers/complain.rb b/spec/mspec/lib/mspec/matchers/complain.rb index 71b6a77680..4bcb255040 100644 --- a/spec/mspec/lib/mspec/matchers/complain.rb +++ b/spec/mspec/lib/mspec/matchers/complain.rb @@ -7,44 +7,48 @@ class ComplainMatcher def matches?(proc) @saved_err = $stderr - @stderr = $stderr = IOStub.new @verbose = $VERBOSE - $VERBOSE = false - - proc.call + begin + err = $stderr = IOStub.new + $VERBOSE = false + Thread.current[:in_mspec_complain_matcher] = true + proc.call + ensure + $VERBOSE = @verbose + $stderr = @saved_err + Thread.current[:in_mspec_complain_matcher] = false + end + @warning = err.to_s unless @complaint.nil? case @complaint when Regexp - return false unless $stderr =~ @complaint + return false unless @warning =~ @complaint else - return false unless $stderr == @complaint + return false unless @warning == @complaint end end - return $stderr.empty? ? false : true - ensure - $VERBOSE = @verbose - $stderr = @saved_err + return @warning.empty? ? false : true end def failure_message if @complaint.nil? ["Expected a warning", "but received none"] elsif @complaint.kind_of? Regexp - ["Expected warning to match: #{@complaint.inspect}", "but got: #{@stderr.chomp.inspect}"] + ["Expected warning to match: #{@complaint.inspect}", "but got: #{@warning.chomp.inspect}"] else - ["Expected warning: #{@complaint.inspect}", "but got: #{@stderr.chomp.inspect}"] + ["Expected warning: #{@complaint.inspect}", "but got: #{@warning.chomp.inspect}"] end end def negative_failure_message if @complaint.nil? - ["Unexpected warning: ", @stderr.chomp.inspect] + ["Unexpected warning: ", @warning.chomp.inspect] elsif @complaint.kind_of? Regexp - ["Expected warning not to match: #{@complaint.inspect}", "but got: #{@stderr.chomp.inspect}"] + ["Expected warning not to match: #{@complaint.inspect}", "but got: #{@warning.chomp.inspect}"] else - ["Expected warning: #{@complaint.inspect}", "but got: #{@stderr.chomp.inspect}"] + ["Expected warning: #{@complaint.inspect}", "but got: #{@warning.chomp.inspect}"] end end end |