Search code examples
rubyruby-on-rails-3capybarasite-prism

SitePrism gem- how to set_url dynamically based on the environment?


I'm converting the in-browser tests for an app to use the SitePrism gem. In the gem readme, I see the following:

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

I anticipate needing to run these tests in multiple environments (i.e. locally, and on a staging server). I'm wondering how I would call Capybara's app_host method dynamically. Would I add something like this to my spec_helper file?

Capybara.app_host = ENV[URL]

Thanks.


Solution

  • I'd do it in rails_helper, after loading the environment, eg:

    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