Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6319523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:49:13+00:00 2026-05-24T15:49:13+00:00

I have an app that uses subdomains to switch databases (multi-tenancy). I’m trying to

  • 0

I have an app that uses subdomains to switch databases (multi-tenancy). I’m trying to use Capybara for integration testing, and it really relies a lot on subdomains.

My understanding was that setting Capybara.default_host= to something would make all my requests come from this host. This doesn’t seem to be the case. In this post, the author recommends just visiting the explicit url with a host, but this becomes a bit annoying if I’m navigating all over the place. I’d like to just set the host, then be able to use my rails paths as expected. Not sure what I’m doing wrong, but here’s what I’ve tried:

# spec_helper.rb
RSpec.configure do |config|
  config.before(:each, :type => :request) do
    Capybara.default_host = 'http://app.mydomain.com'
  end
end

# in some_integration_spec.rb
before do
  puts "Capybara.default_host: #{Capybara.default_host}"
  puts "some_app_url: #{some_app_url}"
end

This yields the output:

Capybara.default_host: http://app.mydomain.com
some_app_url: http://www.example.com/some_path

What am I doing wrong? default_host appears to do nothing. As I say, I don’t want to have to say visit(Capybara.default_host + some_app_path) as that’s a bit annoying each time. Why else does this default_host option exist?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:49:13+00:00Added an answer on May 24, 2026 at 3:49 pm

    I’m not sure of the intended use of default_host, but app_host does what you need. I’ve found I first need to call the rails session method host! in order to set the host string that will be passed to controllers in the request object.

    Then you need to set Capybara.app_host to tell Capybara to call your app via the web server instead of just making the calls in process. If you don’t do that then Capybara wigs out when it encounters redirects and drops the host information in the second request.

    I’m not sure why this doesn’t take care of the Rails request end of things automatically, but I’ve found that unless I set the host in both places explicitly, then I get inconsistent results.

    def set_host (host)
      host! host
      Capybara.app_host = "http://" + host
    end
    
    before(:each) do
      set_host "lvh.me:3000"
    end
    

    Then you can just use relative paths to access pages.

    Update:

    Capybara 2.x and rspec-rails 2.12.0 introduced “Feature” specs for running Capybara acceptance tests. The new FeatureExampleGroup module in rspec-rails is different from RequestExampleGroup and no longer has access to the rack-test host! method. Now you want to use default_url_options instead:

    def set_host (host)
      # host! host
      default_url_options[:host] = host
      Capybara.app_host = "http://" + host
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails3 app that uses subdomains. To allow logins etc. to work
I have an app that uses subdomains for each 'account'. From what I have
We have an app that uses simple one way binding with a GridView to
I have an app that uses EF. To test my stuff I generally wrap
I have an app that uses the python/c api and I was wondering what
I have an app that uses a tableview, along with a UIButton that I
I have a App that uses the In App feature. -(void) completeTransaction: (skPaymenttransaction *)transaction{
I have an app that uses the iPhone camera and puts an overlay over
I have an app that uses Spring security and BlazeDS. Flex 3.2 is used
So I have an app that uses the Zend amazon web services client. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.