Skip to content

Latest commit

 

History

History
62 lines (38 loc) · 1.77 KB

README.md

File metadata and controls

62 lines (38 loc) · 1.77 KB

Rolling your Own Mocks and Stubs

Presentations

2014/03/13 Tokyo Rails

About the Presentation

RSpec and mocha give you great tools for stubbing and mocking the behavior of your dependencies to give you all of the benefits of isolated testing.

Over-relying on these techniques, however, can bind the interface of your mocks to your specs, and allow them to more easily fall out-of-line with the expectations of your real objects. There's a better way!

By looking at the quality and understandability of your specs, you can better understand how to group functionality and not mix levels of abstractions—specs shouldn't be ugly or hard to change!

This talk uses an example of processing payments from Stripe.

Running The Examples

You can run all of the examples that I use in the talk.

You'll need Ruby 2.1 to run the code. You can use rvm or rbenv to upgrade your Ruby version.

To get started, first install the gems:

$ bundle install

then, you can toggle between the versions of the code I presented (versions 1 through 8):

$ ./switch_version 3

and execute the specs to see that they pass:

$ rspec spec

Try editing them to add your own features or specs!

Resources

Gems

Articles & Documentation