Created
July 28, 2011 16:08
-
-
Save stephancom/1111833 to your computer and use it in GitHub Desktop.
Example of problem with rspec 2 + rails 3.1 + ruby 1.9.2 + factory_girl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gem 'rails', '3.1.0.rc4' | |
| group :development, :test do | |
| gem 'rspec-rails', '~> 2.6.1' | |
| end | |
| group :test do | |
| gem 'factory_girl_rails' | |
| gem 'rspec' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| factory_girl (2.0.1) | |
| factory_girl_rails (1.1.0) | |
| factory_girl (~> 2.0.0) | |
| railties (>= 3.0.0) | |
| ... | |
| rspec (2.6.0) | |
| rspec-core (~> 2.6.0) | |
| rspec-expectations (~> 2.6.0) | |
| rspec-mocks (~> 2.6.0) | |
| rspec-core (2.6.4) | |
| rspec-expectations (2.6.0) | |
| diff-lcs (~> 1.1.2) | |
| rspec-mocks (2.6.0) | |
| rspec-rails (2.6.1) | |
| actionpack (~> 3.0) | |
| activesupport (~> 3.0) | |
| railties (~> 3.0) | |
| rspec (~> 2.6.0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class OtherModel < ActiveRecord::Base | |
| after_create :some_slow_method, :on => :create | |
| private | |
| def some_slow_method | |
| # do something that takes a while | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'spec_helper' | |
| describe OtherModel do | |
| before(:each) do | |
| @other_model = Factory.create :other_model | |
| end | |
| it "should work right" do | |
| @other_model.true_thing.should be_true | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| stephan$ ruby -v ; rails -v ; rspec -v | |
| ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0] | |
| Rails 3.1.0.rc4 | |
| 2.6.4 | |
| stephan$ rspec spec/models/some_model_spec.rb spec/models/other_model_spec.rb | |
| .F | |
| Failures: | |
| 1) Comment | |
| Failure/Error: @other_model = Factory(:other_model) | |
| NameError: | |
| undefined local variable or method `some_slow_method' for #<OtherModel:0x00000106ff72e0> | |
| # ./spec/models/comment_spec.rb:5:in `block (2 levels) in <top (required)>' | |
| Finished in xx.xx seconds | |
| 2 examples, 1 failure | |
| stephan$ rspec spec/models/other_model_spec.rb spec/models/some_model_spec.rb | |
| .. | |
| Finished in xx.xx seconds | |
| 2 examples, 0 failures |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'spec_helper' | |
| describe SomeModel do | |
| before(:each) do | |
| OtherModel.any_instance.stub(:some_slow_method) | |
| @some_model = Factory.create :some_model | |
| end | |
| it "should handle some_model normally" do | |
| @some_model.true_thing.should be_true | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LOTS of detail has been omitted here. I've experimented with lots of different settings in my gemfile, including working straight from master. The terminal output is faked, based on my real output, to illustrate the issue.
seems like it may be related to rspec/rspec-mocks#54
also tried unstubbing manually in an after(:all) or after(:each) block, wonder if it's related to this as well: rspec/rspec-mocks#68