Read more

Stubbed class methods in RSpec 1 remain stubbed in other examples

Henning Koch
June 12, 2011Software engineer at makandra GmbH

I encountered a bug in RSpec 1.x where stubbed class methods ("static methods") would not be unstubbed before the next example, causing it to fail. This behavior can come and go as you edit your specs, since this can change the order in which RSpec evaluates your .rb files.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

I was not able to find a fix for this behavior. Calling #rspec_reset und #unstub!(:method) on the class after the example did not help. I know for sure that stubbing static methods has not been a problem in many other projects. I encountered the bug while working on Cucumber Factory Show archive.org snapshot .

This might be fixed Show archive.org snapshot in RSpec 2.

Posted by Henning Koch to makandra dev (2011-06-12 14:17)