Running tests sometimes may take long time. In the post I’ll explain how to reduce the time spent to run tests.
For this purpose there is a nice tool called spork. Spork forks a copy of the server each time you run your tests.
To use spork in your Rails application first you should add it to your Gemfile:
Or certainly you can use gem install command as well.
Then run bundle install. After installing the gem you should configure it. In this post I will show configuration with rspec,
therefor you should have rspec among your gems. To configure spork with rspec run the following command(you should be in your application main directory).
Now your app’s spec_helper.rb file should be as following:
Then read all the instructions. As noted in instructions we should move all appropriate loading to spork each block. So our new spec_helper.rb file
should be as below:
Now start your spork server via spork command and it will let you run your rspec tests faster by providing –drb command : rspec –drb spec/