Skip to content

Instantly share code, notes, and snippets.

@iamnader
Created September 15, 2010 17:55
Show Gist options
  • Save iamnader/581146 to your computer and use it in GitHub Desktop.
Save iamnader/581146 to your computer and use it in GitHub Desktop.
### subdomain_test.rb
require 'integration_test_helper'
class SubdomainTest < ActionController::IntegrationTest
test "simple subdomain test" do
sub1 = "sub1"
sub2 = "sub2"
# this test passes using selenium
#Capybara.current_driver = :selenium
Capybara.app_host = "http://#{sub1}.lvh.me:9887"
visit "/" # ApplicationController gets a request url of 'http://lvh.me', what is set in the Capybara.default_host
p current_url # equals 'http://lvh.me'
assert current_url.include?(sub1)
Capybara.app_host = "http://#{sub2}.lvh.me:9887"
visit "/"
assert current_url.include?(sub2)
end
end
### integration_test_helper.rb
require "test_helper"
require "capybara/rails"
require "akephalos"
module ActionController
class IntegrationTest
include Capybara
#### SETUP & TEARDOWN
def setup
Capybara.reset_sessions!
end
end
end
Capybara.javascript_driver = :akephalos
Capybara.default_host = "lvh.me"
Capybara.app_host = "http://lvh.me:9887"
### test_helper.rb
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'factory_girl'
require 'mongoid'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment