1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
5 describe "failing MockArgumentConstraints" do
7 @mock = mock("test mock")
8 @reporter = Mock.new("reporter", :null_object => true)
15 it "should reject non boolean" do
16 @mock.should_receive(:random_call).with(boolean())
18 @mock.random_call("false")
19 end.should raise_error(MockExpectationError)
22 it "should reject non numeric" do
23 @mock.should_receive(:random_call).with(an_instance_of(Numeric))
25 @mock.random_call("1")
26 end.should raise_error(MockExpectationError)
29 it "should reject non string" do
30 @mock.should_receive(:random_call).with(an_instance_of(String))
32 @mock.random_call(123)
33 end.should raise_error(MockExpectationError)
36 it "should reject goose when expecting a duck" do
37 @mock.should_receive(:random_call).with(duck_type(:abs, :div))
38 lambda { @mock.random_call("I don't respond to :abs or :div") }.should raise_error(MockExpectationError)
41 it "should fail if regexp does not match submitted string" do
42 @mock.should_receive(:random_call).with(/bcd/)
43 lambda { @mock.random_call("abc") }.should raise_error(MockExpectationError)
46 it "should fail if regexp does not match submitted regexp" do
47 @mock.should_receive(:random_call).with(/bcd/)
48 lambda { @mock.random_call(/bcde/) }.should raise_error(MockExpectationError)
51 it "should fail for a hash w/ wrong values" do
52 @mock.should_receive(:random_call).with(:a => "b", :c => "d")
54 @mock.random_call(:a => "b", :c => "e")
55 end.should raise_error(MockExpectationError, /Mock 'test mock' expected :random_call with \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\) but received it with \(\{(:a=>\"b\", :c=>\"e\"|:c=>\"e\", :a=>\"b\")\}\)/)
58 it "should fail for a hash w/ wrong keys" do
59 @mock.should_receive(:random_call).with(:a => "b", :c => "d")
61 @mock.random_call("a" => "b", "c" => "d")
62 end.should raise_error(MockExpectationError, /Mock 'test mock' expected :random_call with \(\{(:a=>\"b\", :c=>\"d\"|:c=>\"d\", :a=>\"b\")\}\) but received it with \(\{(\"a\"=>\"b\", \"c\"=>\"d\"|\"c\"=>\"d\", \"a\"=>\"b\")\}\)/)
65 it "should match against a Matcher" do
67 @mock.should_receive(:msg).with(equal(3))
69 end.should raise_error(MockExpectationError, "Mock 'test mock' expected :msg with (equal 3) but received it with (37)")
72 it "should fail no_args with one arg" do
74 @mock.should_receive(:msg).with(no_args)
76 end.should raise_error(MockExpectationError, "Mock 'test mock' expected :msg with (no args) but received it with (37)")
80 describe "failing deprecated MockArgumentConstraints" do
82 @mock = mock("test mock")
83 @reporter = Mock.new("reporter", :null_object => true)
91 it "should reject non boolean" do
92 @mock.should_receive(:random_call).with(:boolean)
94 @mock.random_call("false")
95 end.should raise_error(MockExpectationError)
98 it "should reject non numeric" do
99 @mock.should_receive(:random_call).with(:numeric)
101 @mock.random_call("1")
102 end.should raise_error(MockExpectationError)
105 it "should reject non string" do
106 @mock.should_receive(:random_call).with(:string)
108 @mock.random_call(123)
109 end.should raise_error(MockExpectationError)