This post will demonstrate how I setup rails for bdd. I mainly use 3 gems spork, rspec and cucumber.
Why Spork?
I use spork to run my tests faster. I experianced 2x to 5x faster test running time when I use spork. My Gemfile look similar to the below one.
The Setup
So I added all the needed gems to my Gemfile and now its time to setup rspec and cucumber. Now setup rspec and cucumber with the below commands which will generate related files and directory structure.
Now you need to setup spork for rspec and cucumber.
The above command will generate spork.prefork
and spork.eachrun
blocks in the spec/spec_helper.rb
. Now you need to manually move the code generated by rails g rspec:install
into the spork.prefork
block.
As you done for rspec, the above command will generate the spork.prefork
and spork.eachrun
blocks in the features/support/env.rb
and you need to move the code generated by rails g cucumber:install
into the spork.prefork
block.
Now its time to setup guard, which will watch your application code and tests and run the tests when ever you update the code/tests.
This above command will generate Guardfile and add configuration for spork, rspec and cucumber.
Then you need to add cli: '--drb'
to rspec and cucmber guard configuration, to run them over the Spork DRb server.
An example configuration with cli option will look like,
Thats it. My bdd setup for rails is done.