带有黄瓜导轨的数据库清理器事务 [英] database cleaner transaction with cucumber rails

查看:19
本文介绍了带有黄瓜导轨的数据库清理器事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?

解决方案

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

这篇关于带有黄瓜导轨的数据库清理器事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆