Created
February 21, 2014 18:03
-
-
Save linko/9139640 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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