Search code examples
ruby-on-railsrspeccapybara

Testing subdomains in capybara/rspec


I'm currently almost at the end of a long journey into rails testing, but I'm banging my head on how to get request specs working with subdomains.

In development, I'm using pow with urls such as: http://teddanson.myapp.dev/account which is all fine and dandy.

In testing, I let capybara do it's thing which returns localhost http://127.0.0.1:50568/account which obviously doesn't play nice with the whole subdomain thing. It works fine for the public part of the app that doesn't require subdomains, but how to access a given user's subdomain account is beyond me.

The relevant routes are accessed via these methods:

class Public
  def self.matches?(request)
    request.subdomain.blank? || request.subdomain == 'www'
  end
end

class Accounts
  def self.matches?(request)
    request.subdomain.present? && request.subdomain != 'www'
  end
end

I feel like I'm taking crazy pills, so if anyone has any advice or suggestions to help me out that'd be very, very awesome. Thanks for your help!


Solution

  • You can use xip.io to test subdomains in Capybara/RSpec, as described here: https://web.archive.org/web/20171222062651/http://chrisaitchison.com/2013/03/17/testing-subdomains-in-rails/