2014/03/13 Tokyo Rails
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.
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!
Gems
Articles & Documentation