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
8 it "should == expected" do
9 "this".should == "this"
10 Spec::Matchers.generated_description.should == "should == \"this\""
13 it "should not == expected" do
14 "this".should_not == "that"
15 Spec::Matchers.generated_description.should == "should not == \"that\""
18 it "should be empty (arbitrary predicate)" do
20 Spec::Matchers.generated_description.should == "should be empty"
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"
28 it "should be true" do
30 Spec::Matchers.generated_description.should == "should be true"
33 it "should be false" do
35 Spec::Matchers.generated_description.should == "should be false"
40 Spec::Matchers.generated_description.should == "should be nil"
45 Spec::Matchers.generated_description.should == "should be > 3"
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"
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"
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"
67 expected.should equal(expected)
68 Spec::Matchers.generated_description.should == "should equal \"expected\""
71 it "should_not equal" do
72 5.should_not equal(37)
73 Spec::Matchers.generated_description.should == "should not equal 37"
77 "string".should eql("string")
78 Spec::Matchers.generated_description.should == "should eql \"string\""
81 it "should not eql" do
82 "a".should_not eql(:a)
83 Spec::Matchers.generated_description.should == "should not eql :a"
86 it "should have_key" do
87 {:a => "a"}.should have_key(:a)
88 Spec::Matchers.generated_description.should == "should have key :a"
91 it "should have n items" do
92 team.should have(3).players
93 Spec::Matchers.generated_description.should == "should have 3 players"
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"
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"
106 it "should include" do
107 [1,2,3].should include(3)
108 Spec::Matchers.generated_description.should == "should include 3"
112 "this string".should match(/this string/)
113 Spec::Matchers.generated_description.should == "should match /this string/"
116 it "should raise_error" do
117 lambda { raise }.should raise_error
118 Spec::Matchers.generated_description.should == "should raise Exception"
121 it "should raise_error with type" do
122 lambda { raise }.should raise_error(RuntimeError)
123 Spec::Matchers.generated_description.should == "should raise RuntimeError"
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\""
131 it "should respond_to" do
132 [].should respond_to(:insert)
133 Spec::Matchers.generated_description.should == "should respond to #insert"
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"
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"