]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/spec/spec/mocks/passing_mock_argument_constraints_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 / mocks / passing_mock_argument_constraints_spec.rb
1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
3 module Spec
4   module Mocks
5     describe "mock argument constraints", :shared => true do
6       before(:each) do
7         @mock = Mock.new("test mock")
8         Kernel.stub!(:warn)
9       end
10       
11       after(:each) do
12         @mock.rspec_verify
13       end
14     end
15     
16     describe Methods, "handling argument constraints with DEPRECATED symbols" do
17       it_should_behave_like "mock argument constraints"
18
19       it "should accept true as boolean" do
20         @mock.should_receive(:random_call).with(:boolean)
21         @mock.random_call(true)
22       end
23       
24       it "should accept false as boolean" do
25         @mock.should_receive(:random_call).with(:boolean)
26         @mock.random_call(false)
27       end
28
29       it "should accept fixnum as numeric" do
30         @mock.should_receive(:random_call).with(:numeric)
31         @mock.random_call(1)
32       end
33
34       it "should accept float as numeric" do
35         @mock.should_receive(:random_call).with(:numeric)
36         @mock.random_call(1.5)
37       end
38
39       it "should accept string as anything" do
40         @mock.should_receive(:random_call).with("a", :anything, "c")
41         @mock.random_call("a", "whatever", "c")
42       end
43
44       it "should match string" do
45         @mock.should_receive(:random_call).with(:string)
46         @mock.random_call("a string")
47       end
48       
49       it "should match no args against any_args" do
50         @mock.should_receive(:random_call).with(:any_args)
51         @mock.random_call("a string")
52       end
53       
54       it "should match no args against no_args" do
55         @mock.should_receive(:random_call).with(:no_args)
56         @mock.random_call
57       end
58     end
59
60     describe Methods, "handling argument constraints" do
61       it_should_behave_like "mock argument constraints"
62
63       it "should accept true as boolean()" do
64         @mock.should_receive(:random_call).with(boolean())
65         @mock.random_call(true)
66       end
67
68       it "should accept false as boolean()" do
69         @mock.should_receive(:random_call).with(boolean())
70         @mock.random_call(false)
71       end
72
73       it "should accept fixnum as an_instance_of(Numeric)" do
74         @mock.should_receive(:random_call).with(an_instance_of(Numeric))
75         @mock.random_call(1)
76       end
77
78       it "should accept float as an_instance_of(Numeric)" do
79         @mock.should_receive(:random_call).with(an_instance_of(Numeric))
80         @mock.random_call(1.5)
81       end
82
83       it "should accept string as anything()" do
84         @mock.should_receive(:random_call).with("a", anything(), "c")
85         @mock.random_call("a", "whatever", "c")
86       end
87
88       it "should match duck type with one method" do
89         @mock.should_receive(:random_call).with(duck_type(:length))
90         @mock.random_call([])
91       end
92
93       it "should match duck type with two methods" do
94         @mock.should_receive(:random_call).with(duck_type(:abs, :div))
95         @mock.random_call(1)
96       end
97       
98       it "should match no args against any_args()" do
99         @mock.should_receive(:random_call).with(any_args)
100         @mock.random_call()
101       end
102       
103       it "should match one arg against any_args()" do
104         @mock.should_receive(:random_call).with(any_args)
105         @mock.random_call("a string")
106       end
107       
108       it "should match no args against no_args()" do
109         @mock.should_receive(:random_call).with(no_args)
110         @mock.random_call()
111       end
112     end
113     
114     describe Methods, "handling non-constraint arguments" do
115
116       it "should match non special symbol (can be removed when deprecated symbols are removed)" do
117         @mock.should_receive(:random_call).with(:some_symbol)
118         @mock.random_call(:some_symbol)
119       end
120
121       it "should match string against regexp" do
122         @mock.should_receive(:random_call).with(/bcd/)
123         @mock.random_call("abcde")
124       end
125
126       it "should match regexp against regexp" do
127         @mock.should_receive(:random_call).with(/bcd/)
128         @mock.random_call(/bcd/)
129       end
130       
131       it "should match against a hash submitted and received by value" do
132         @mock.should_receive(:random_call).with(:a => "a", :b => "b")
133         @mock.random_call(:a => "a", :b => "b")
134       end
135       
136       it "should match against a hash submitted by reference and received by value" do
137         opts = {:a => "a", :b => "b"}
138         @mock.should_receive(:random_call).with(opts)
139         @mock.random_call(:a => "a", :b => "b")
140       end
141       
142       it "should match against a hash submitted by value and received by reference" do
143         opts = {:a => "a", :b => "b"}
144         @mock.should_receive(:random_call).with(:a => "a", :b => "b")
145         @mock.random_call(opts)
146       end
147       
148       it "should match against a Matcher" do
149         @mock.should_receive(:msg).with(equal(37))
150         @mock.msg(37)
151       end
152     end
153   end
154 end