Skip to content

Stubs vs Mocks

January 18, 2012

stubs vs mocks

  • stub creates an object with method that return those values
  • stubs just blindly return a value. mocks have expectations. and so they can cause a test to fail.
  • think of mocks as blackboxing an object. they are not real instances of any model.
  • a mock object responds ONLY to the expectations you set on it, nothing more, nothing less
  • we try to write everything as unit tests. Even our controller tests, which some people test as functional tests, we test as unit tests.
  • expectation IS a test. So if you do not want to use that, use stubs. example: @object.expects(:method_name).twice.returns(@other_object) over @object.stubs(:method_name).returns(@other_object)
Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: