Testing Subdomains in Capybara

chrisconley

Chris Conley

2 years ago · 1,319 views
scenario "Home page should display the current tenant's name" do
    Capybara.current_session.driver.reset!
    Capybara.default_host = 'tenant1'

    visit '/'
    page.should have_content("Welcome to Tenant1")

    Capybara.current_session.driver.reset!
    Capybara.default_host = 'tenant2'

    visit '/'
    page.should have_content("Welcome to Tenant 2")
  end
Raw

Although this post on testing subdomains with Capybara pointed me in the right direction, it may have been written for an older version of Capybara. The reason is that Capybara::Server.manual_host never was utilized.

Instead, I came up with this simpler(imo) solution: Just reset the current driver and assign a new default host.

You could even write a helper method that wraps those two lines to make it even cleaner!

This has only been tested with the rack-test driver and may not work with Culerity, Selenium, etc.

Tagged: capybara rails rspec ruby steak subdomains
Comments are only visible to Forrst members. Log in or Request an invite.
3 new notifications