1 require File.dirname(__FILE__) + '/../spec_helper'
2 require 'mspec/expectations/expectations'
3 require 'mspec/matchers/complain'
5 describe ComplainMatcher do
6 it "matches when executing the proc results in output to $stderr" do
7 proc = lambda { warn "I'm gonna tell yo mama" }
8 ComplainMatcher.new(nil).matches?(proc).should == true
11 it "maches when executing the proc results in the expected output to $stderr" do
12 proc = lambda { warn "Que haces?" }
13 ComplainMatcher.new("Que haces?\n").matches?(proc).should == true
14 ComplainMatcher.new("Que pasa?\n").matches?(proc).should == false
15 ComplainMatcher.new(/Que/).matches?(proc).should == true
16 ComplainMatcher.new(/Quoi/).matches?(proc).should == false
19 it "does not match when there is no output to $stderr" do
20 ComplainMatcher.new(nil).matches?(lambda {}).should == false
23 it "provides a useful failure message" do
24 matcher = ComplainMatcher.new(nil)
25 matcher.matches?(lambda { })
26 matcher.failure_message.should == ["Expected a warning", "but received none"]
27 matcher = ComplainMatcher.new("listen here")
28 matcher.matches?(lambda { warn "look out" })
29 matcher.failure_message.should ==
30 ["Expected warning: \"listen here\"", "but got: \"look out\""]
31 matcher = ComplainMatcher.new(/talk/)
32 matcher.matches?(lambda { warn "listen up" })
33 matcher.failure_message.should ==
34 ["Expected warning to match:", "/talk/"]
37 it "provides a useful negative failure message" do
38 proc = lambda { warn "ouch" }
39 matcher = ComplainMatcher.new(nil)
40 matcher.matches?(proc)
41 matcher.negative_failure_message.should ==
42 ["Unexpected warning: ", "\"ouch\""]
43 matcher = ComplainMatcher.new("ouchy")
44 matcher.matches?(proc)
45 matcher.negative_failure_message.should ==
46 ["Expected warning: \"ouchy\"", "but got: \"ouch\""]
47 matcher = ComplainMatcher.new(/ou/)
48 matcher.matches?(proc)
49 matcher.negative_failure_message.should ==
50 ["Expected warning not to match:", "/ou/"]