Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / spec / spec / matchers / description_generation_spec.rb
blobd1246ad04f1fb839987eab3ec0df160ae8074ab1
1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
3 describe "Matchers should be able to generate their own descriptions" do
4   before(:each) do
5     @desc = nil
6     @callback = lambda { |desc| @desc = desc }
7     Spec::Matchers.description_generated(@callback)
8   end
9   
10   it "should == expected" do
11     "this".should == "this"
12     @desc.should == "should == \"this\""
13   end
14   
15   it "should not == expected" do
16     "this".should_not == "that"
17     @desc.should == "should not == \"that\""
18   end
19   
20   it "should be empty (arbitrary predicate)" do
21     [].should be_empty
22     @desc.should == "should be empty"
23   end
24   
25   it "should not be empty (arbitrary predicate)" do
26     [1].should_not be_empty
27     @desc.should == "should not be empty"
28   end
29   
30   it "should be true" do
31     true.should be_true
32     @desc.should == "should be true"
33   end
34   
35   it "should be false" do
36     false.should be_false
37     @desc.should == "should be false"
38   end
39   
40   it "should be nil" do
41     nil.should be_nil
42     @desc.should == "should be nil"
43   end
44   
45   it "should be > n" do
46     5.should be > 3
47     @desc.should == "should be > 3"
48   end
49   
50   it "should be predicate arg1, arg2 and arg3" do
51     5.0.should be_between(0,10)
52     @desc.should == "should be between 0 and 10"
53   end
55   it "should be_few_words predicate should be transformed to 'be few words'" do
56     5.should be_kind_of(Fixnum)
57     @desc.should == "should be kind of Fixnum"
58   end
60   it "should preserve a proper prefix for be predicate" do
61     5.should be_a_kind_of(Fixnum)
62     @desc.should == "should be a kind of Fixnum"
63     5.should be_an_instance_of(Fixnum)
64     @desc.should == "should be an instance of Fixnum"
65   end
66   
67   it "should equal" do
68     expected = "expected"
69     expected.should equal(expected)
70     @desc.should == "should equal \"expected\""
71   end
72   
73   it "should_not equal" do
74     5.should_not equal(37)
75     @desc.should == "should not equal 37"
76   end
77   
78   it "should eql" do
79     "string".should eql("string")
80     @desc.should == "should eql \"string\""
81   end
82   
83   it "should not eql" do
84     "a".should_not eql(:a)
85     @desc.should == "should not eql :a"
86   end
87   
88   it "should have_key" do
89     {:a => "a"}.should have_key(:a)
90     @desc.should == "should have key :a"
91   end
92   
93   it "should have n items" do
94     team.should have(3).players
95     @desc.should == "should have 3 players"
96   end
97   
98   it "should have at least n items" do
99     team.should have_at_least(2).players
100     @desc.should == "should have at least 2 players"
101   end
102   
103   it "should have at most n items" do
104     team.should have_at_most(4).players
105     @desc.should == "should have at most 4 players"
106   end
107   
108   it "should include" do
109     [1,2,3].should include(3)
110     @desc.should == "should include 3"
111   end
112   
113   it "should match" do
114     "this string".should match(/this string/)
115     @desc.should == "should match /this string/"
116   end
117   
118   it "should raise_error" do
119     lambda { raise }.should raise_error
120     @desc.should == "should raise Exception"
121   end
122   
123   it "should raise_error with type" do
124     lambda { raise }.should raise_error(RuntimeError)
125     @desc.should == "should raise RuntimeError"
126   end
127   
128   it "should raise_error with type and message" do
129     lambda { raise "there was an error" }.should raise_error(RuntimeError, "there was an error")
130     @desc.should == "should raise RuntimeError with \"there was an error\""
131   end
132   
133   it "should respond_to" do
134     [].should respond_to(:insert)
135     @desc.should == "should respond to #insert"
136   end
137   
138   it "should throw symbol" do
139     lambda { throw :what_a_mess }.should throw_symbol
140     @desc.should == "should throw a Symbol"
141   end
142   
143   it "should throw symbol (with named symbol)" do
144     lambda { throw :what_a_mess }.should throw_symbol(:what_a_mess)
145     @desc.should == "should throw :what_a_mess"
146   end
147   
148   def team
149     Class.new do
150       def players
151         [1,2,3]
152       end
153     end.new
154   end
155   
156   after(:each) do
157     Spec::Matchers.unregister_description_generated(@callback)
158   end