Search code examples
ruby-on-railsactiverecordrspec-rails

Loading only ActiveRecord for RSpec model tests


I want to speed up my model tests. After seeing this http://iain.nl/testing-activerecord-in-isolation, I thought it could be achieved if i can only require the active_record rather than loading the spec_helper.rb, which loads the whole Rails stack for every test file. I am using rspec-rails with factory_girl. But so far its not working for me. Every time i run a single file the whole migrations are getting run, which is not acceptable.And before the whole migrations run i am getting some errors. Anybody have a better idea?


Solution

  • If you're looking to speed up your tests by not having to reload the Rails environment each time, you should look into using Spork, Guard, and Guard::Spork. Spork allows you to run a separate, "clean" test server, while Guard enables you to keep it running in the background by observing your files for changes.

    Spork: https://github.com/sporkrb/spork

    Guard::Spork: https://github.com/guard/guard-spork

    The ever-helpful Railscast: http://railscasts.com/episodes/285-spork