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