【问题标题】:FixtureReplacement with Cucumber用黄瓜替换夹具
【发布时间】:2009-10-21 09:05:58
【问题描述】:

我将 Cucumber 与 Selenium、FixtureReplacement 和 DatabaseCleaner 一起使用。

有趣的是,我使用 FixtureReplacement 创建的数据无法从我的测试中访问。

我为 selenium 添加了自己的 rails 环境,并且我正在使用自己的配置文件来增强 selenium 功能。 我对 selenium 配置文件的黄瓜设置是:

Webrat.configure do |config|
  config.mode = :selenium
  config.application_environment = :selenium
end

Cucumber::Rails::World.use_transactional_fixtures = false

require "database_cleaner"

# Clean the database once when starting
DatabaseCleaner.clean_with :truncation
DatabaseCleaner.strategy = :truncation

Before do
  DatabaseCleaner.start
  include FixtureReplacement
end

After do
  DatabaseCleaner.clean
end

# this is necessary to have webrat "wait_for" the response body to be available
# when writing steps that match against the response body returned by selenium
World(Webrat::Selenium::Matchers)

FixtureReplacement 效果很好,我已经在 Rails 控制台中测试过了。

我正在运行我的 selenium 功能:

RAILS_ENV=selenium cucumber -p selenium features/enhanced/test.feature

有人知道这个问题的解决方案吗?

最好的问候

【问题讨论】:

  • 你试过黄瓜和 Watir 吗? vimeo.com/2871256
  • 您说 FixtureReplacement 在 Rails 控制台中有效,但在您的测试环境或硒环境中有效。我的第一个猜测是 FixtureReplacement 仅在测试中加载,而不是在硒中。但我对 FixtureReplacement 一无所知。
  • FixtureReplacement 是一个 Rails 插件,因此它会在每个环境中加载。另外,我看了一下它的源代码,测试环境没有限制。

标签: ruby-on-rails cucumber fixtures


【解决方案1】:

我想知道您是否正确使用了 Database Cleaner?在我的 env.rb 中,我是这样使用它的:

Before do
  require 'database_cleaner'
  require 'database_cleaner/cucumber'
  DatabaseCleaner.strategy = :truncation
end

这在使用 Factory Girl 时适用于我。

【讨论】:

  • 这对我也不起作用。你能发布你的整个 Cucumber 设置吗?
  • 顺便说一句,我已经变成了工厂女孩。
  • 这里有一个要点:gist.github.com/215924 基本上:* 在测试环境中运行功能(也许不是一个好主意)* 关闭事务固定装置 * 配置 Webrat 以使用 selenium(带有一些特定于我的设置) * 需要工厂女孩(也许你缺少一点?) * 在 Before 钩子中定义数据库清理器。希望对您有所帮助,广告。
【解决方案2】:

这与夹具无关。我以为我无法访问我的数据,因为我无法登录。

以下修复了它: Cucumber + selenium fails randomly

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-16
    • 2013-10-21
    • 2021-04-17
    • 2017-11-13
    相关资源
    最近更新 更多