RSpec, Mocha, and Shoulda

The latest release of shoulda-matchers, 1.4.2, now requires Mocha.  I’ve been using the RSpec stubbing library, but adding mocha to the project breaks one little part of RSpec stubbing.  While Mocha uses stubs to stub a method and RSpec uses stub, both use unstub if you need to unstub a single method.  This collision causes problems if you’re using RSpec to create the stub, because the call to unstub uses Mocha which then promptly fails to remove the RSpec stub!

The solution is to use the RSpec alias unstub! wherever you need to remove an RSpec stub – since Mocha doesn’t implement unstub!, you can continue to happily use the RSpec stubbing library and still successfully unstub RSpec stubs.

Advertisements

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