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