Skip to content

Instantly share code, notes, and snippets.

@rewinfrey
Forked from turadg/subdomains.rb
Last active August 29, 2015 14:20
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 rewinfrey/e96ae9f361c569ff1ebe to your computer and use it in GitHub Desktop.
Save rewinfrey/e96ae9f361c569ff1ebe 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
# (e.g. save as spec/support/subdomains.rb)
def switch_to_subdomain(subdomain)
# lvh.me always resolves to 127.0.0.1
hostname = subdomain ? "#{subdomain}.lvh.me" : "lvh.me"
Capybara.app_host = "http://#{hostname}"
end
def switch_to_main_domain
switch_to_subdomain nil
end
RSpec.configure do |config|
switch_to_main_domain
end
Capybara.configure do |config|
config.always_include_port = true
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
describe "Main domain", js: true do
it "should test the primary domain" do
switch_to_main_domain
visit root_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment