SitePrism gem-如何基于环境动态set_url?

时间:2014-08-13 17:20:57

标签: ruby ruby-on-rails-3 capybara site-prism

我正在将应用程序的浏览器内测试转换为使用SitePrism 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]

感谢。

1 个答案:

答案 0 :(得分: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