database cleaner transaction with cucumber rails

試著忘記壹切 提交于 2019-12-10 10:58:05

问题


I am writing a scenario for signup 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 database cleaner to roll back the test database after this scenario so that I can use this scenario again and again.

For that 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 scenario , the user gets saved in the database and the database cleaner fails. I dont see any error messages

  • Could you please clarify how to use database cleaner for only one scenario.I only want to use cleaner for this scenario.
  • Also could you please also provide the vital difference between using truncation and transaction.I think truncation clears the whole database but I dont want that.
  • Is there a better method of doing signup testing than this?

回答1:


You can't run transactions with selenium because the test runs on two separate instances of the app AFAIK



来源:https://stackoverflow.com/questions/7511520/database-cleaner-transaction-with-cucumber-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!