Skip to content

Instantly share code, notes, and snippets.

@MattHall
Forked from rtekie/subdomains.rb
Created May 12, 2013 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattHall/5564827 to your computer and use it in GitHub Desktop.
Save MattHall/5564827 to your computer and use it in GitHub Desktop.
# Support for Rspec / Capybara subdomain integration testing
# Make sure this file is required by spec_helper.rb
#
# Sample subdomain test:
# it "should test subdomain" do
# switch_to_subdomain("mysubdomain")
# visit root_path
# end
DEFAULT_HOST = "lvh.me"
DEFAULT_PORT = 9887
RSpec.configure do |config|
Capybara.default_host = "http://#{DEFAULT_HOST}"
Capybara.server_port = DEFAULT_PORT
Capybara.app_host = "http://#{DEFAULT_HOST}:#{Capybara.server_port}"
end
def switch_to_subdomain(subdomain)
Capybara.app_host = "http://#{subdomain}.#{DEFAULT_HOST}:#{DEFAULT_PORT}"
end
# Sample spec file
require 'spec_helper'
describe "Subdomains", :js => true do
it "should test subdomain" do
switch_to_subdomain("mysubdomain")
visit root_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment