1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
5 describe "mock argument constraints", :shared => true do
7 @mock = Mock.new("test mock")
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)
23 it "should accept false as boolean" do
24 @mock.should_receive(:random_call).with(:boolean)
25 @mock.random_call(false)
28 it "should accept fixnum as numeric" do
29 @mock.should_receive(:random_call).with(:numeric)
33 it "should accept float as numeric" do
34 @mock.should_receive(:random_call).with(:numeric)
35 @mock.random_call(1.5)
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")
43 it "should match string" do
44 @mock.should_receive(:random_call).with(:string)
45 @mock.random_call("a string")
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")
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)
62 it "should accept false as boolean()" do
63 @mock.should_receive(:random_call).with(boolean())
64 @mock.random_call(false)
67 it "should accept fixnum as an_instance_of(Numeric)" do
68 @mock.should_receive(:random_call).with(an_instance_of(Numeric))
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)
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")
82 it "should match duck type with one method" do
83 @mock.should_receive(:random_call).with(duck_type(:length))
87 it "should match duck type with two methods" do
88 @mock.should_receive(:random_call).with(duck_type(:abs, :div))
92 it "should match no args against any_args()" do
93 @mock.should_receive(:random_call).with(any_args)
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")
102 it "should match no args against no_args()" do
103 @mock.should_receive(:random_call).with(no_args)
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)
115 it "should match string against regexp" do
116 @mock.should_receive(:random_call).with(/bcd/)
117 @mock.random_call("abcde")
120 it "should match regexp against regexp" do
121 @mock.should_receive(:random_call).with(/bcd/)
122 @mock.random_call(/bcd/)
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")
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")
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)
142 it "should match against a Matcher" do
143 @mock.should_receive(:msg).with(equal(37))