I want to access user1.application.local.dev/panel/new from a steak spec.
How do I do it?
Step 1. Set up a local DNS.
http://intridea.com/2010/6/2/using-bind-locally-on-os-x-for-easy-access-to-subdomains?blog=company
Step 2. Use a Capybara driver that support subdomains.
Either Selenium or Akephalos would do the trick.
Create spec/support/custom_env and put this content in it:
#Capybara.default_driver = :selenium
Capybara.default_driver = :akephalos
Capybara.app_host = 'http://davinci.testing.dev:8082'
Capybara.run_server = false
Capybara.server_port = 8082
Select the capybara driver that you want, either Selenium or akpehalos or whatever you want, except rack-test (default)
Put the domain and port of you choice, of course.
Step 3:
Add the config.before block to your spec/spec_helper.rb
RSpec.configure do |config|
config.before :each do
Capybara.app_host = "http://davinci.testing.dev:8082"
end
end
Put the domain and port of you choice, of course.
Step 4:
Add a helper to switch subdomains.
Spec/acceptance/support/helpers.rb
def switch_to_subdomain(subdomain)
Capybara.app_host = "http://#{subdomain}.davinci.testing.dev:8082"
end
Put the domain and port of you choice, of course.
Step 5. Use the helper method in your spec.
Now every-time you want to change of subdomain you do:
scenario "Show school" do
school = School.make!(:name=>"perico")
switch_to_subdomain(school.name)
visit("/")
page.has_content?("Welcome to perico")
end
This is a Capybara question. Set the default_host
when you need it
Capybara.default_host = 'sub.domain.com'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With