title: Testing multidomain Rails 3 app with Capybara
body: <p>I want to test my multidomain RoR3 App.</p>
  
  <p>Here's my test_helper.rb</p>
  
  <pre><code>ENV["RAILS_ENV"] = "test"
  
  require File.expand_path('../../config/environment', __FILE__)
  require 'rails/test_help'
  require 'capybara/rails'
  require 'blueprints'
  
  class ActiveSupport::TestCase
  
  end
  
  class ActionDispatch::IntegrationTest
    include Capybara
  
    def host
      "http://#{subdomain}.lvh.me:3000"
    end
  
    def subdomain
      @subdomain ? @subdomain : 'demostore'
    end
  
    def visit(url)
      super("http://#{subdomain}.lvh.me:3000#{url}")
    end
  end
  </code></pre>
  
  <p>And my integration test:</p>
  
  <pre><code>require 'test_helper'
  
  class ProductsTest &lt; ActionDispatch::IntegrationTest
  
    def setup
      @subdomain = 'demostore'
      # creating stuff
    end
  
    def teardown
      # deleting stuff
    end
  
    test "user views product list" do
      visit('/')
      assert page.has_css?('ul.product-listing')
      assert page.has_xpath?("//ul[@class='product-listing']/li", :count =&gt; 12)
    end
  
    test "user views product page" do
      product = Product.first
  
      visit('/')
      find(:xpath, "//ul[@class='product-listing']/li/a[1]").click
      save_and_open_page
    end
  
  end
  </code></pre>
  
  <p>And I'm sure the link exists. There is problem with clicking and filling stuff.</p>
  
  <pre><code>click_link('Existent link title')
  </code></pre>
  
  <p>doesn't work too.</p>
  
  <p>I think the default Capybara's driver Rack::Test could have problems with this multidomain stuff?</p>