Cucumber / rails error uninitialized constant DatabaseCleaner (NameError)

Does anyone know what causes this error when running cucumber features ?

 uninitialized constant DatabaseCleaner (NameError) 
+9
source share
4 answers

DatabaseCleaner is a library to "clean up" your db. Cucumber will use it between working functions so that your db is in a checked state (i.e. empty).

The idea is that you create the right data in your Given sentences for each test.

This error means that DatabaseCleaner is not required properly.

Different versions of Rails / Cucumber have different ways to configure everything and provide different functionality in this regard, so it is difficult for you to give the right solution without knowing the settings.

A few tips:

Take a look at the cucumber-rails gem. This gives you a lot of nice things, like generators as well as a rake, so you can run rake cucumber instead of using cucumber directly. Often generators will create a configuration file that requires database_cleaner .

Otherwise, add database_cleaner to the dependency list and place require 'database_cleaner' somewhere in your test case code.

+3
source

Add this line to your gemfile:

 gem 'database_cleaner' 

This is because cucumber-rails does not automatically depend on database_cleaner , because you can create a Rails application without a database, and therefore you must explicitly require it.

+14
source

I just experienced this problem. I downgraded my cucumber jewelry to version 1.0.6, and received this message:

 uninitialized constant Cucumber::Rails::Database (NameError) 

when I use cucumber 1.0.6 (not the latest version) and database_cleaner v. 1.7.0. To fix the error, I simply run this command (in Rails 3.1.3):

 rails g cucumber:install 

You will be prompted to replace the features/support/env.rb . Just answer with Y , and you can run rake cucumber:ok again.

+1
source

I use spring, and spring stop work for me

0
source

All Articles