【问题标题】:Rails testing with Watir. How do I load my test db with the fixtures from /test/fixtures使用 Watir 进行 Rails 测试。如何使用 /test/fixtures 中的夹具加载我的测试数据库
【发布时间】:2011-10-02 18:18:09
【问题描述】:

我正在尝试使用 Watir 使用测试装置测试我的 Rails 应用程序。 watir 测试有效,但我似乎无法使用 /test/fixtures 中的夹具加载我的测试数据库。

我尝试使用带有 RAILS_ENV=test 的 rake 任务,但只能从 /db/fixtures/ 加载固定装置

【问题讨论】:

  • 如果您找到了方法,您还需要帮助吗?如果不是,您可能希望将您的发现放入“答案”或只是删除问题,而不是将其留在这里看起来没有答案
  • 嗯,然后接受你的回答。

标签: ruby-on-rails watir fixtures


【解决方案1】:

找到了一种使用 rake 任务的方法。

namespace :watir do
  desc "Initiate the db for watir tests" 
  task :db_reset do
    if (ENV['RAILS_ENV'] == "test")
      Rake::Task["db:test:prepare"].invoke
      Rake::Task["db:test:load"].invoke
      Rake::Task["db:seed"].invoke
      Rake::Task["db:fixtures:load"].invoke("FIXTURES=x,y,z,....") #x,y,z are the name of the fixtures in test/fixtures/*
    else
      puts "Must be executed with test flag ('RAILS_ENV=test')"
    end
  end
end

要运行它,我会 rake watir:db_reset

现在我可以在测试装置上运行 watir 测试

【讨论】:

  • #其中 x,y,z 是 test/fixtures/* 中的灯具名称
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-21
  • 2020-11-01
  • 2015-07-31
  • 1970-01-01
  • 2013-09-15
  • 1970-01-01
相关资源
最近更新 更多