# Gemfile
group :development, :test do
gem 'rspec-rails', '~> 3.0.0'
gem 'factory_girl_rails'
gem 'capybara'
gem 'database_cleaner'
end
$ rails generate rspec:install
To make Capybara available from within RSpec specs, add the following line to spec/rails_helper.rb:
# spec/rails_helper.rb
require 'capybara/rails'
Your Capybara feature specs will also need a home. Add the spec/features/ directory:
mkdir spec/features
Or You Can run:
$ rails generate rspec:feature [test_name]
then it will test under spec/features
Next, make the following adjustments to spec/rails_helper.rb to integrate the database_cleaner gem:
# spec/rails_helper
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
To make the factory_girl gem’s methods (e.g., build and create) easily available in RSpec examples, add this line to the top of your RSpec.configure block in spec/rails_helper.rb:
# spec/rails_helper.rb
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
# other configurations below...
end