Topic: rspec with factory_girl rails broken

I am developing the 'sample_app' application from Michael Hartl's rails tutorial (www.railstutorial.org) site. The code with rspec tests ran fine in my mac, but after cloning from git into my linux vm it fails. Here is the output. I even made sure my code was not the contributing factor by cloning the author's app and running the tests, still no joy.


rspec ./spec/spec_helper.rb
/home/user/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/runtime.rb:31:in `block in setup': You have already activated rspec-core 2.5.2, but your Gemfile requires rspec-core 2.0.0.beta.18. Consider using bundle exec. (Gem::LoadError)
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/spec_set.rb:12:in `block in each'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/spec_set.rb:12:in `each'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/spec_set.rb:12:in `each'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/runtime.rb:17:in `setup'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler.rb:107:in `setup'
    from /home/user/projects/sample_app/config/boot.rb:8:in `<top (required)>'
    from /home/user/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/user/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/user/projects/sample_app/config/application.rb:1:in `<top (required)>'
    from /home/user/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/user/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/user/projects/sample_app/config/environment.rb:2:in `<top (required)>'
    from /home/user/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/user/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/user/projects/sample_app/spec/spec_helper.rb:4:in `<top (required)>'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/configuration.rb:386:in `load'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/configuration.rb:386:in `block in load_spec_files'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/configuration.rb:386:in `map'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/configuration.rb:386:in `load_spec_files'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:18:in `run'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:55:in `run_in_process'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:46:in `run'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:10:in `block in autorun'



In the first line, it says I have a newer version of rspec-core/expectations etc, so what I did was to remove everything and use the version that was out when I started building the app - it was 2.0.0-beta18. It woks fine without errors.

Re: rspec with factory_girl rails broken

You most likely have some compatibility conflicts with your gems requirements, if you do like the first line suggests and run bundle exec with your rake spec command all should be good.

I have had this issue before which I resolved by ensuring that all my gems were up to date and older gems were cleaned up (removed)
I now follow the rvm best practices guide and have had no issues since using this
http://beginrescueend.com/rvm/best-practices/
also if you are using Rails 3 make sure you are using rspec_rails rather than rspec gem

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: rspec with factory_girl rails broken

I would also encourage you to update the version of rspec in your Gemfile to a much more current, latest, version.