本文介绍了MiniTest,水豚,夹具,Database_Cleaner在第二次未通过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下测试第一次通过(在 rake db:test:prepare 之后),但在随后的运行中给出了错误。

The following test passed first time (after rake db:test:prepare) but gave error on subsequent run.



require "test_helper"

DatabaseCleaner.strategy = :transaction

class SaleFeatureTest < Capybara::Rails::TestCase
  include Warden::Test::Helpers
  Warden.test_mode!

  self.use_transactional_fixtures = false

  setup do
    login_as users(:admin), scope: :user
    Capybara.current_driver = :selenium #:webkit
    DatabaseCleaner.start
  end

  teardown do
    DatabaseCleaner.clean
    Warden.test_reset!
  end

  test "Sale" do        
    visit(new_sale_path) # create new sale and redirect to it
    assert page.has_css?('#sale_payment_btn') # gave error at second time
    find(:css, '#sale_payment_btn').click # this create payment
  end

当我将硒和铬一起使用时,我可以看到销售的ID。我注意到该ID对于后续测试是相同的。即 980190963

As I used selenium with chrome, I could see the ID of the sale. I noticed that the ID was the same for subsequent test. i.e. 980190963

我的理论是


  1. database_cleaner 无法正常工作。 (尽管我在 test.log 文件中看到了DB清理sql命令,但我看到数据仍保留在数据库中)

  1. database_cleaner not functioning as expected. (Although I see DB cleaning sql commands on test.log file, I saw data remained in database)

访问不会创建新的 @sale (如,尽管我使用的是minitest),因为 #sal_payment_btn 不呈现(销售在第一次运行时已经有个付款)。

visit does not create new @sale (as stated here though I use minitest) because #sal_payment_btn is not rendered (sale already has payment on first run).

我现在把头发拉了半天。我已经尝试过

I'm pulling my hair around for half day now. I have tried


  • webkit 驱动程序

  • 不同的清理策略截断删除

  • webkit driver
  • different cleaning strategy truncation, deletion

,但我仍然无法通过第二次测试。

and I still can't pass the test on second run. It is running okay on manual test.

我在哪里做错了什么?

P.S。我正在使用以下宝石

P.S. I'm using the following gems

minitest-rails-capybara
selenium-webdriver
chromedriver-helper
database_cleaner
minitest-around
pg

我已阅读以下




  • 设为
  • http://blog.berylliumwork.com/2013/07/rails-4-devise-3-minitest-and-capybara.html
  • Database Cleaner not working in minitest rails
  • Rails minitest, database cleaner how to turn use_transactional_fixtures = false

推荐答案

我已确认问题是我的 database_cleaner

:交易策略不适用于我的设置黄瓜 + webkit / 。更改为:删除策略。

:transaction strategy was not working for my setup cucumber+webkit/selenium. Changed to :deletion strategy.

看来我学习不够。我在寻找答案的过程中发现了以下内容。

It seemed I didn't study enough. I found out the following during my search for answer.


  1. 有人问-没有答案

指出


  • 表示:transaction 策略会增加工作量

  • database_cleaner readme stated that :transaction strategy imposes bit more working




  • 其他值得阅读的东西





    • 最推荐的方式使用 rails rspec ,<$ c设置 database_cleaner $ c>水豚-


    • Other worthy reading

      • Why you should be using Database Cleaner's deletion strategy
      • most recommended way to set up database_cleaner with rails, rspec, capybara and selenium - http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and-selenium/
      • Rails 4, Devise 3, MiniTest and Capybara for user login
      • 这篇关于MiniTest,水豚,夹具,Database_Cleaner在第二次未通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    10-20 07:51