1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
3 describe "Matchers should be able to generate their own descriptions" do
6 @callback = lambda { |desc| @desc = desc }
7 Spec::Matchers.description_generated(@callback)
10 it "should == expected" do
11 "this".should == "this"
12 @desc.should == "should == \"this\""
15 it "should not == expected" do
16 "this".should_not == "that"
17 @desc.should == "should not == \"that\""
20 it "should be empty (arbitrary predicate)" do
22 @desc.should == "should be empty"
25 it "should not be empty (arbitrary predicate)" do
26 [1].should_not be_empty
27 @desc.should == "should not be empty"
30 it "should be true" do
32 @desc.should == "should be true"
35 it "should be false" do
37 @desc.should == "should be false"
42 @desc.should == "should be nil"
47 @desc.should == "should be > 3"
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"
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"
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"
69 expected.should equal(expected)
70 @desc.should == "should equal \"expected\""
73 it "should_not equal" do
74 5.should_not equal(37)
75 @desc.should == "should not equal 37"
79 "string".should eql("string")
80 @desc.should == "should eql \"string\""
83 it "should not eql" do
84 "a".should_not eql(:a)
85 @desc.should == "should not eql :a"
88 it "should have_key" do
89 {:a => "a"}.should have_key(:a)
90 @desc.should == "should have key :a"
93 it "should have n items" do
94 team.should have(3).players
95 @desc.should == "should have 3 players"
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"
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"
108 it "should include" do
109 [1,2,3].should include(3)
110 @desc.should == "should include 3"
114 "this string".should match(/this string/)
115 @desc.should == "should match /this string/"
118 it "should raise_error" do
119 lambda { raise }.should raise_error
120 @desc.should == "should raise Exception"
123 it "should raise_error with type" do
124 lambda { raise }.should raise_error(RuntimeError)
125 @desc.should == "should raise RuntimeError"
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\""
133 it "should respond_to" do
134 [].should respond_to(:insert)
135 @desc.should == "should respond to #insert"
138 it "should throw symbol" do
139 lambda { throw :what_a_mess }.should throw_symbol
140 @desc.should == "should throw a Symbol"
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"
157 Spec::Matchers.unregister_description_generated(@callback)