Anyone have any idea what is causing this error when running cucumber features
?
uninitialized constant DatabaseCleaner (NameError)
Add this line to your Gemfile:
gem 'database_cleaner'
This is because cucumber-rails
doesn't automatically depend on database_cleaner
because you may be building a Rails application without a database, and so you must explicitly require it.
DatabaseCleaner is a library for 'cleaning' your db. Cucumber will use it between running features to ensure your db is in a testable state (ie. empty).
The idea is that you build up the proper data in your Given
clauses for each test
This error just means that DatabaseCleaner hasn't been required properly.
Different versions of Rails/Cucumber have different ways of configuring everything and provide different functionality with this regard so it's hard to actually give you the right solution without knowing your setup.
A couple of tips though:
Look at the cucumber-rails gem. It gives you lots of nice stuff such as generators and also rake tasks so you can run rake cucumber
instead of using cucumber directly. Often times the generators will build a config file that requires database_cleaner
for you.
Otherwise, add database_cleaner
to your list of dependencies and put a require 'database_cleaner'
somewhere in your test suite code.
I just experienced the problem. I downgraded my cucumber gems to version 1.0.6, and I got 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. For fixing the error, I just run this command (on Rails 3.1.3):
rails g cucumber:install
It will prompt you to replace file features/support/env.rb
. Just answer with Y
and you can run rake cucumber:ok
again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With