Anton Zolotov

I'm a software developer, entrepreneur and CEO of GunpowderLabs, a web and mobile development consultancy. Contact me.

The difference between mocks and stubs

A stub replaces a method with code that returns a specified result.

let(:user) { User.create! }
controller.stub(:current_user).and_return(user)

A mock is a stub with an expectation that the method gets called.

User.should_receive(:find).with(1).and_return(user)

blog comments powered by Disqus