1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
3 describe "Matchers should be able to generate their own descriptions" do
5 Spec::Matchers.clear_generated_description
9 Spec::Matchers.clear_generated_description
12 it "should == expected" do
13 "this".should == "this"
14 Spec::Matchers.generated_description.should == "should == \"this\""
17 it "should not == expected" do
18 "this".should_not == "that"
19 Spec::Matchers.generated_description.should == "should not == \"that\""
22 it "should be empty (arbitrary predicate)" do
24 Spec::Matchers.generated_description.should == "should be empty"
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"
32 it "should be true" do
34 Spec::Matchers.generated_description.should == "should be true"
37 it "should be false" do
39 Spec::Matchers.generated_description.should == "should be false"
44 Spec::Matchers.generated_description.should == "should be nil"
49 Spec::Matchers.generated_description.should == "should be > 3"
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"
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"
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"
71 expected.should equal(expected)
72 Spec::Matchers.generated_description.should == "should equal \"expected\""
75 it "should_not equal" do
76 5.should_not equal(37)
77 Spec::Matchers.generated_description.should == "should not equal 37"
81 "string".should eql("string")
82 Spec::Matchers.generated_description.should == "should eql \"string\""
85 it "should not eql" do
86 "a".should_not eql(:a)
87 Spec::Matchers.generated_description.should == "should not eql :a"
90 it "should have_key" do
91 {:a => "a"}.should have_key(:a)
92 Spec::Matchers.generated_description.should == "should have key :a"
95 it "should have n items" do
96 team.should have(3).players
97 Spec::Matchers.generated_description.should == "should have 3 players"
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"
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"
110 it "should include" do
111 [1,2,3].should include(3)
112 Spec::Matchers.generated_description.should == "should include 3"
116 "this string".should match(/this string/)
117 Spec::Matchers.generated_description.should == "should match /this string/"
120 it "should raise_error" do
121 lambda { raise }.should raise_error
122 Spec::Matchers.generated_description.should == "should raise Exception"
125 it "should raise_error with type" do
126 lambda { raise }.should raise_error(RuntimeError)
127 Spec::Matchers.generated_description.should == "should raise RuntimeError"
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\""
135 it "should respond_to" do
136 [].should respond_to(:insert)
137 Spec::Matchers.generated_description.should == "should respond to #insert"
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"
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"