Cleaning up the database with cucumber rails
I am writing a script for a registration form.
@abc
@selenium
Scenario:Non registered user signs up
Given I am on the sign-up page
When I fill in the following:
|first_name|Anidhya|
|last_name|Ahuja|
|email|anidhya@gmail.com|
|password|123456|
And I press "submit"
Then I should see "Registration complete"
I want to use a database cleaner to rollback a test database after this script so that I can use this script over and over again.
To do this, inside my env.rb file, I wrote:
begin
require 'database_cleaner'
require 'database_cleaner/cucumber'
DatabaseCleaner.strategy = :transaction
Cucumber::Rails::World.use_transactional_fixtures = true
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
Before('@abc') do
DatabaseCleaner.start
end
After('@abc') do
DatabaseCleaner.clean
end
Now when I run the script, the user gets saved in the database and the database cleanup fails. I don't see any error messages
- Could you please explain how to use the database cleaner for just one scenario. I only want to use a cleaner for this scenario.
- Also you could also point out the significant difference between using truncation and a transaction. I think that truncation cleans up the entire database, but I don't want that.
- Is there a better way to do registration testing than this?
+2
source to share