Updated to latest rspec
[gitorious:georgyos-clone.git] / vendor / plugins / rspec / 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       
113       it "should match hash with hash_including same hash" do
114         @mock.should_receive(:random_call).with(hash_including(:a => 1))
115         @mock.random_call(:a => 1)
116       end
117         
118     end
119     
120     describe Methods, "handling non-constraint arguments" do
121
122       it "should match non special symbol (can be removed when deprecated symbols are removed)" do
123         @mock.should_receive(:random_call).with(:some_symbol)
124         @mock.random_call(:some_symbol)
125       end
126
127       it "should match string against regexp" do
128         @mock.should_receive(:random_call).with(/bcd/)
129         @mock.random_call("abcde")
130       end
131
132       it "should match regexp against regexp" do
133         @mock.should_receive(:random_call).with(/bcd/)
134         @mock.random_call(/bcd/)
135       end
136       
137       it "should match against a hash submitted and received by value" do
138         @mock.should_receive(:random_call).with(:a => "a", :b => "b")
139         @mock.random_call(:a => "a", :b => "b")
140       end
141       
142       it "should match against a hash submitted by reference and received by value" do
143         opts = {:a => "a", :b => "b"}
144         @mock.should_receive(:random_call).with(opts)
145         @mock.random_call(:a => "a", :b => "b")
146       end
147       
148       it "should match against a hash submitted by value and received by reference" do
149         opts = {:a => "a", :b => "b"}
150         @mock.should_receive(:random_call).with(:a => "a", :b => "b")
151         @mock.random_call(opts)
152       end
153       
154       it "should match against a Matcher" do
155         @mock.should_receive(:msg).with(equal(37))
156         @mock.msg(37)
157       end
158     end
159   end
160 end