RSpec stub question

Hi

I am using Mongoid. In Mongoid while saving a record we typically give
like in the controller
@post.safely.save
For a model class Post

I am writing rspecs for my controller and want to mock the model. So
what I am doing is

let(:post) { mock_model(Post).as_null_object }

before(:each) do
Post.stub(:new).and_return(post)
end
it “creates new post”
Post.should_receive(:new).and_return(post)
end

#how do I stub safely.save also here and test whether it receives save
call?

Thanks
Arun

On Sat, May 14, 2011 at 12:13 AM, arunsark
[email protected]wrote:

let(:post) { mock_model(Post).as_null_object }

Thanks
Arun


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Hi, check out “stub_chain”

http://relishapp.com/rspec/rspec-mocks/v/2-6/dir/method-stubs/stub-a-chain-of-methods