Steps for TDD setup and execution

1. On creating project tells Rails not to generate a test directory associated with the default Test::Unit framework. we will be using an alternate testing framework called RSpec to write a thorough test suite.

  rails new [project name] --skip-test-unit

2. Add Gems:
Add following gem in development mode so that we have access to RSpec-specific generators, and it includes it in test mode in order to run the tests. We don’t have to install RSpec itself because it is a dependency of rspec-rails and will thus be installed automatically:

  group :development, :test do
    .
    .
    gem 'rspec-rails', '2.11.0'
    .
    .
  end

Include the Capybara gem in test mode, which allows us to simulate a user’s interaction with the application using a natural English-like syntax.

  group :test do
    gem 'capybara', '1.1.2'
  end

To install and include the new gems, we run bundle update and bundle install

  bundle update
  bundle install --without production

3. Next, we need to configure Rails to use RSpec in place of Test::Unit. This can be accomplished with:

  rails generate rspec:install

If your system complains about the lack of a JavaScript runtime, visit the execjs page at GitHub for a list of possibilities. I particularly recommend installing Node.js.

4. Genrate controller with following command to suppress the generation of the default RSpec tests, which we won’t be using. Instead, we’ll create the tests by hand

  rails g controller [controller name] --no-test-framework

5. Generate an integration test (request spec) for our abc pages:

  rails generate integration_test abc_pages

Above command will create file abc_pages_spec.rb in spec/request directory

6. Write test cases in above created file. (how to write test case have a look at: …)

7. Excute Test cases:

  bundle exec rspec spec/requests/abc_pages_spec.rb

to run specific test

 bundle exec rspec spec/requests/abc_pages_spec.rb -e "[test case name]" 

For automate the running of the tests use ‘Guard’ gem.
You can speed up tests execution by using ‘Spork’ gem.

Advertisements

One thought on “Steps for TDD setup and execution

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s