Skip to content

Instantly share code, notes, and snippets.

@linko
Created February 21, 2014 18:03
Show Gist options
  • Save linko/9139640 to your computer and use it in GitHub Desktop.
Save linko/9139640 to your computer and use it in GitHub Desktop.
# spec/support/capybara.rb
require 'capybara/rspec'
require 'capybara/rails'
Capybara.javascript_driver = :webkit
Capybara.app_host = 'lvh.me'
Capybara.always_include_port = true
# spec/support/host_for_subdomains.rb
def hosted_domain(options = {})
path = options[:path] || '/' # use root path by default
subdomain = options[:subdomain].present? ? (options[:subdomain]+'.') : ''
if example.metadata[:js]
# figures out which port Capybara spun up on the "rails s -e test" command
# ** note: on Capybara 2.x you can use Capybara.always_use_port in the spec_helper
url = "http://#{subdomain}lvh.me#{path}"
else
url = "http://#{subdomain}example.com" + path
end
end
# Usage example
def login_as_publisher(publisher=nil)
@publisher = publisher
@publisher ||= create :publisher
visit hosted_domain path: new_publisher_session_path, subdomain: 'publisher'
within '#loginform' do
fill_in 'publisher_email', with: @publisher.email
fill_in 'publisher_password', with: 'password'
click_button 'Login'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment