Step 1. Configure the local DNS.
http://intridea.com/2010/6/2/using-bind-locally-on-os-x-for-easy-access-to-subdomains?blog=company
Step 2. Use the Capybara driver, which supports subdomains.
Selenium or Akefalos will do the trick.
Create spec / support / custom_env and put this content in it:
#Capybara.default_driver = :selenium Capybara.default_driver = :akephalos Capybara.app_host = 'http://davinci.testing.dev:8082' Capybara.run_server = false Capybara.server_port = 8082
Select the capybara driver you want, either Selenium, or akpehalos, or anything except rack verification (default)
Of course, indicate your domain and port.
Step 3:
Add config.before block to your spec / spec_helper.rb
RSpec.configure do | config |
config.before: everyone does Capybara.app_host = " http://davinci.testing.dev:8082 " end
end
Of course, indicate your domain and port.
Step 4:
Add a helper to switch subdomains.
Spec / reception / support / helpers.rb
def switch_to_subdomain(subdomain) Capybara.app_host = "http://#{subdomain}.davinci.testing.dev:8082" end
Of course, indicate your domain and port.
Step 5. Use the helper method in your specification.
Now every time you want to change the subdomain that you do:
scenario "Show school" do school = School.make!(:name=>"perico") switch_to_subdomain(school.name) visit("/") page.has_content?("Welcome to perico") end