1

我正在将应用程序的浏览器内测试转换为使用 SitePrism gem。在 gem 自述文件中,我看到以下内容:

A page usually has a URL. If you want to be able to navigate to a page, you'll need to set its URL. Here's how:

    class Home < SitePrism::Page
      set_url "http://www.google.com"
    end

If you've set Capybara's app_host then you can set the URL as follows:

    class Home < SitePrism::Page
      set_url "/home.htm"
    end

我预计需要在多个环境(即本地和临时服务器上)运行这些测试。我想知道如何动态调用 Capybara 的 app_host 方法。我会在我的 spec_helper 文件中添加这样的内容吗?

Capybara.app_host = ENV[URL]

谢谢。

4

1 回答 1

1

rails_helper加载环境后,我会在其中执行此操作,例如:

case Rails.env
when "test"
  # use default
when "staging"
  Capybara.app_host = "http://www.google.com"
else
  raise "could not set app_host for environment: #{Rails.env}"
end
于 2014-08-14T23:56:49.540 回答