1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
5 describe "mock argument constraints", :shared => true do
7 @mock = Mock.new("test mock")
16 describe Methods, "handling argument constraints with DEPRECATED symbols" do
17 it_should_behave_like "mock argument constraints"
19 it "should accept true as boolean" do
20 @mock.should_receive(:random_call).with(:boolean)
21 @mock.random_call(true)
24 it "should accept false as boolean" do
25 @mock.should_receive(:random_call).with(:boolean)
26 @mock.random_call(false)
29 it "should accept fixnum as numeric" do
30 @mock.should_receive(:random_call).with(:numeric)
34 it "should accept float as numeric" do
35 @mock.should_receive(:random_call).with(:numeric)
36 @mock.random_call(1.5)
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")
44 it "should match string" do
45 @mock.should_receive(:random_call).with(:string)
46 @mock.random_call("a string")
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")
54 it "should match no args against no_args" do
55 @mock.should_receive(:random_call).with(:no_args)
60 describe Methods, "handling argument constraints" do
61 it_should_behave_like "mock argument constraints"
63 it "should accept true as boolean()" do
64 @mock.should_receive(:random_call).with(boolean())
65 @mock.random_call(true)
68 it "should accept false as boolean()" do
69 @mock.should_receive(:random_call).with(boolean())
70 @mock.random_call(false)
73 it "should accept fixnum as an_instance_of(Numeric)" do
74 @mock.should_receive(:random_call).with(an_instance_of(Numeric))
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)
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")
88 it "should match duck type with one method" do
89 @mock.should_receive(:random_call).with(duck_type(:length))
93 it "should match duck type with two methods" do
94 @mock.should_receive(:random_call).with(duck_type(:abs, :div))
98 it "should match no args against any_args()" do
99 @mock.should_receive(:random_call).with(any_args)
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")
108 it "should match no args against no_args()" do
109 @mock.should_receive(:random_call).with(no_args)
114 describe Methods, "handling non-constraint arguments" do
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)
121 it "should match string against regexp" do
122 @mock.should_receive(:random_call).with(/bcd/)
123 @mock.random_call("abcde")
126 it "should match regexp against regexp" do
127 @mock.should_receive(:random_call).with(/bcd/)
128 @mock.random_call(/bcd/)
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")
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")
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)
148 it "should match against a Matcher" do
149 @mock.should_receive(:msg).with(equal(37))