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