Rails:不同环境的特定 rake 任务依赖关系

发布于 2024-09-27 06:09:39 字数 578 浏览 0 评论 0原文

我的主 rakefile 有一些任务来停止和启动 selenuim,如下所示:

require 'selenium/rake/tasks'

Selenium::Rake::RemoteControlStartTask.new do |rc|
  rc.port = 4444
  rc.timeout_in_seconds = 3 * 60
  rc.background = false
  rc.wait_until_up_and_running = true
  rc.additional_args << "-singleWindow"
end

Selenium::Rake::RemoteControlStopTask.new do |rc|
  rc.host = "localhost"
  rc.port = 4444
  rc.timeout_in_seconds = 3 * 60
end

这强制要求安装 selenuim gem 才能使用 rake,无论 轨道环境。我可以在哪里放置此代码,以便仅在将 Rails 环境设置为测试时才加载它?

Rails 2.3

干杯

My main rakefile has some tasks to stop and start selenuim as follows:

require 'selenium/rake/tasks'

Selenium::Rake::RemoteControlStartTask.new do |rc|
  rc.port = 4444
  rc.timeout_in_seconds = 3 * 60
  rc.background = false
  rc.wait_until_up_and_running = true
  rc.additional_args << "-singleWindow"
end

Selenium::Rake::RemoteControlStopTask.new do |rc|
  rc.host = "localhost"
  rc.port = 4444
  rc.timeout_in_seconds = 3 * 60
end

This forces the requirement to have the selenuim gem installed to use rake regardless of the
rails environment. Where can I put this code so it will only be loaded when the rails environment is set to test?

Rails 2.3

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

内心旳酸楚 2024-10-04 06:09:39

您使用的是 Rails 3 还是 Rails 2?

Rails 3 添加了如下所示的块:

if Rails.env.test?
  require 'selenium/rake/tasks'

  Selenium::Rake::RemoteControlStartTask.new do |rc|
    rc.port = 4444
    rc.timeout_in_seconds = 3 * 60
    rc.background = false
    rc.wait_until_up_and_running = true
    rc.additional_args << "-singleWindow"
  end

  Selenium::Rake::RemoteControlStopTask.new do |rc|
    rc.host = "localhost"
    rc.port = 4444
    rc.timeout_in_seconds = 3 * 60
  end
end

在 Rails 2(或 3,但已弃用)中,如下所示:

if RAILS_ENV == "test"
  require 'selenium/rake/tasks'

  Selenium::Rake::RemoteControlStartTask.new do |rc|
    rc.port = 4444
    rc.timeout_in_seconds = 3 * 60
    rc.background = false
    rc.wait_until_up_and_running = true
    rc.additional_args << "-singleWindow"
  end

  Selenium::Rake::RemoteControlStopTask.new do |rc|
    rc.host = "localhost"
    rc.port = 4444
    rc.timeout_in_seconds = 3 * 60
  end
end

Are you using Rails 3 or Rails 2?

Rails 3 add a blocks like so:

if Rails.env.test?
  require 'selenium/rake/tasks'

  Selenium::Rake::RemoteControlStartTask.new do |rc|
    rc.port = 4444
    rc.timeout_in_seconds = 3 * 60
    rc.background = false
    rc.wait_until_up_and_running = true
    rc.additional_args << "-singleWindow"
  end

  Selenium::Rake::RemoteControlStopTask.new do |rc|
    rc.host = "localhost"
    rc.port = 4444
    rc.timeout_in_seconds = 3 * 60
  end
end

In Rails 2 (or 3 but it's deprecated) like this:

if RAILS_ENV == "test"
  require 'selenium/rake/tasks'

  Selenium::Rake::RemoteControlStartTask.new do |rc|
    rc.port = 4444
    rc.timeout_in_seconds = 3 * 60
    rc.background = false
    rc.wait_until_up_and_running = true
    rc.additional_args << "-singleWindow"
  end

  Selenium::Rake::RemoteControlStopTask.new do |rc|
    rc.host = "localhost"
    rc.port = 4444
    rc.timeout_in_seconds = 3 * 60
  end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文