[Rspec-devel] rails_plugin_fix merged to trunk

Luke Redpath luke at agileevolved.com
Thu Aug 3 09:47:15 EDT 2006

Hi James

I've encountered a small problem using Stubba with RSpec and Rails.  
It seems - probably due to the way spec_helper.rb works - that  
teardown_with_stubba is being called twice, resulting in no method  
error when it tries to call nil.unstub_all and therefore failing all  

The solution was a simple one, I just added a small guard clause:

   def teardown_with_stubba
     return if $stubba.nil?
     $stubba = nil


> Hi David. I really like what you guys are doing with RSpec. I was
> wondering if you'd seen Stubba (http://mocha.rubyforge.org). It allows
> you to stub class methods like :new and :find and avoid hitting the
> database. Here's a trivial example...
> def test_should_find_expected_product
>   expected_product = Product.new
>   Product.stubs(:find).returns(product)
>   assert_equal expected_product, Product.find(123)
> end
> - The Product class reverts to its original behaviour after each test.
> - You can specify different return values in different tests.
> - The test is explicit, because the return value is defined in the  
> test.
> We're using it on Rails projects at Reevoo.
> James.
> http://blog.floehopper.org
> _______________________________________________
> Rspec-devel mailing list
> Rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel

More information about the Rspec-devel mailing list