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