gpt4 book ai didi

ruby-on-rails-3 - 数据库清理器不清理一个 cucumber 场景

转载 作者:行者123 更新时间:2023-11-28 20:44:35 25 4
gpt4 key购买 nike

所以我的团队正在使用 Cucumber、Rspec 和使用这些测试框架所需的所有 gem 来开发我们的 Rails 应用程序(一个调查和精简版电子记录系统)。我正在设置 Jenkins CI 服务器,并希望在我们的测试、开发和暂存环境中标准化我们的数据库(我们最终选择了 MySQL)。

将测试环境从 SQlite 切换到 MySQL 后,我们发现了一些与缓存相关的测试错误,我们通过使用相对 ID 而不是硬编码来解决这些错误。示例:

describe "#instance_method" do
before(:each) do
@survey = FactoryGirl.create(:survey)
@question_1 = FactoryGirl.create(:question)
@question_2 = FactoryGirl.create(:question)
....
end
context "question has no requirements" do
it "should match" do
# below breaks under MySQL (and postgres), but not SQlite
expect { @survey.present_question?(2) }.to be_true
# always works
expect { @survey.present_question?(@question_2.id) }.to be_true
end
end
end

解决了这个失败的规范后,我解决了一些不相关的 ajax 问题,这些问题一直困扰着我们的测试套件。以为我终于掌握了测试的艺术,我自信地运行了 rake。我遇到了这个不友好的景象:

screen shot 2013-08-20 at 8 12 42 pm

当然 cucumber features/presenting_default_questions.feature 在隔离运行时会下雨。

失败场景:

@javascript
Feature: Dynamic Presentation of Questions
In order to only answer questions that are relevant considering previously answered questions
As a patient
I want to not be presented questions that illogical given my previously answered question on the survey

Scenario: Answering a question that does not depend on any other questions
Given I have the following questions:
| prompt | datatype | options | parent_id | requirement |
| Do you like cars? | bool | | | |
| Do you like fruit? | bool | | | |
When I visit the patient sign in page
And I fill out the form with the name "Jim Dog", date of birth "1978-03-30", and gender "male"
And I accept the waiver
Then I should see the question "Do you like cars"
When I respond to the boolean question with "Yes"
Then I should see the question "Do you like fruit?"
When I respond to the boolean question with "No"
Given I wait for the ajax request to finish
Then I should be on the results page

相关步骤:

Then(/^I should be on the results page$/) do
# fails under ``rake`` passes when run in isolation
current_path.should == results_survey_path(1)
end

Then(/^I should be on the results page$/) do
# passes in isolation and under ``rake``
current_path.should == results_survey_path(Survey.last.id)
end

除了使用 Capybara.javascript_driver = :webkit 之外,cucumber/database cleaner 配置未从 rails g cucumber:install 中修改。

似乎失败的 rspec 和 cucumber 测试都遇到了同样的索引问题。虽然上面提出的解决方案有效,但它非常笨拙,并且回避了为什么简单的绝对索引不起作用的问题(在每个场景和功能之间清理了所有数据库之后)。我的测试有问题吗?使用 database_cleaner?

如果更多代码有帮助,请告诉我!

相关的 gem 版本:

  • 事件模型 (3.2.14)
  • cucumber (1.3.6)
  • cucumber 导轨 (1.3.1)
  • 数据库清理器 (1.0.1)
  • capybara (2.1.0)
  • capybara -webkit (1.0.0)
  • mysql2 (0.3.13)
  • rspec (2.13.0)

最佳答案

问题似乎是您缺少Cucumber 场景的database_cleaner 代码。

你提到你有 RSpec 场景的 database_cleaner 代码,但你似乎缺少 Cucumber 的类似代码的 env.rb:

begin
require 'database_cleaner'
require 'database_cleaner/cucumber'

DatabaseCleaner.strategy = :truncation
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end

Around do |scenario, block|
DatabaseCleaner.cleaning(&block)
end

你有这个代码吗?

关于ruby-on-rails-3 - 数据库清理器不清理一个 cucumber 场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18361484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com