1 require File.dirname(__FILE__) + '/spec_helper'
3 describe "A consumer of a stub" do
4 it "should be able to stub methods on any Object" do
6 obj.stub!(:foobar).and_return {:return_value}
7 obj.foobar.should equal(:return_value)
13 return :original_return
17 describe "A stubbed method on a class" do
18 it "should return the stubbed value" do
19 StubbableClass.stub!(:find).and_return(:stub_return)
20 StubbableClass.find(1).should equal(:stub_return)
23 it "should revert to the original method after each spec" do
24 StubbableClass.find(1).should equal(:original_return)
27 it "can stub! and mock the same message" do
28 StubbableClass.stub!(:msg).and_return(:stub_value)
29 StubbableClass.should_receive(:msg).with(:arg).and_return(:mock_value)
31 StubbableClass.msg.should equal(:stub_value)
32 StubbableClass.msg(:other_arg).should equal(:stub_value)
33 StubbableClass.msg(:arg).should equal(:mock_value)
34 StubbableClass.msg(:another_arg).should equal(:stub_value)
35 StubbableClass.msg(:yet_another_arg).should equal(:stub_value)
36 StubbableClass.msg.should equal(:stub_value)
42 mock = mock("stubbing mock")
43 mock.stub!(:msg).and_return(:value)
44 (1..10).each {mock.msg.should equal(:value)}
47 it "can stub! and mock" do
48 mock = mock("stubbing mock")
49 mock.stub!(:stub_message).and_return(:stub_value)
50 mock.should_receive(:mock_message).once.and_return(:mock_value)
51 (1..10).each {mock.stub_message.should equal(:stub_value)}
52 mock.mock_message.should equal(:mock_value)
53 (1..10).each {mock.stub_message.should equal(:stub_value)}
56 it "can stub! and mock the same message" do
57 mock = mock("stubbing mock")
58 mock.stub!(:msg).and_return(:stub_value)
59 mock.should_receive(:msg).with(:arg).and_return(:mock_value)
60 mock.msg.should equal(:stub_value)
61 mock.msg(:other_arg).should equal(:stub_value)
62 mock.msg(:arg).should equal(:mock_value)
63 mock.msg(:another_arg).should equal(:stub_value)
64 mock.msg(:yet_another_arg).should equal(:stub_value)
65 mock.msg.should equal(:stub_value)