1
votes

I am writing BDD using cucumber for my Rails app but getting problems while running 'cucumber'

My database for test is "test_db". When I run cucumber features/my_Feature_file.feature, it show scenarios pass or fail but along with, It is also cleaning my database.

I am newbie to cucumber. So please tell me that it is default for testing that when you run cucumber, then database will be cleaned. Like If I am writing BDD for user login, So if there will be no any record then how my steps will check that User is valid or not?

I am using:

Gemfile (for test)-

group :test do
  gem 'ZenTest'
  gem 'autotest-rails'
  gem 'autotest-growl'
  gem 'selenium'
  gem 'selenium-client'
  gem 'capybara'
  gem 'database_cleaner'
  gem 'cucumber-rails'
  gem 'cucumber'
  gem 'rspec-rails'
  gem 'spork'
  gem 'xpath'
  gem 'launchy'
  gem 'cucumber-sinatra'
  gem 'webrat'
end

features/support/env.rb-

require 'cucumber/rails'
Capybara.default_selector = :css
ActionController::Base.allow_rescue = false

begin
  DatabaseCleaner.strategy = :transaction
  #DatabaseCleaner.strategy = nil
rescue NameError
  raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end

Cucumber::Rails::Database.javascript_strategy = :truncation

I tried using:

DatabaseCleaner.strategy = nil

and

Cucumber::Rails::World.use_transactional_fixtures = false

Can someone clear my confusions and guide me to the right way? Help is highly appreciated.

2

2 Answers

1
votes

You just have to remove the database_cleaner gem from your Gemfile and clean the env.rb file, if you don't want the database to be cleaned.

I strongly suggest you keep it though. The point of resetting the DB for each scenario is to prove that functionality works from a pristine setting and not because of a pre-existing data condition.

Every scenario should be independent from the other ones.

0
votes

You don't have to use it if you don't want to. We don't have it in our project. You don't need to set use_transactional_fixtures if you don't want to use this either.

If you want to use it, you could start your functional test by registering a new user, and then using this user to verify login and logout. Once your tests are run, then the user will be deleted by DatabaseCleaner at the end.