Created
July 30, 2010 06:49
-
-
Save chrisdarroch/500037 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
# Some handy-dandy sub-domain steps for use with Capybara if you're using SubdomainFu | |
def get_base_url | |
# NOTE: I'm defining SITE_URL higher up somewhere. You might want to change that piece. | |
base_url = SITE_URL.split('.').reject { |piece| SubdomainFu.mirrors.include? piece }.join('.') | |
end | |
When /^(?:|I )visit (.+) for the subdomain "([^\"]*)"$/ do |new_path, subdomain| | |
new_url = get_base_url | |
new_url = subdomain + "." + new_url if subdomain.present? | |
host! new_url | |
Capybara.default_host = host | |
When "I visit #{new_path}" | |
end | |
Then /^(?:|I )should land on the subdomain "([^\"]*)"$/ do |subdomain| | |
current_host = URI.parse(current_url).host | |
if current_host.respond_to? :should | |
current_host.should match /^#{subdomain}/ | |
else | |
assert_match /^#{subdomain}/, current_host | |
end | |
end | |
Then /^(?:|I )should not land on the subdomain "([^\"]*)"$/ do |subdomain| | |
current_host = URI.parse(current_url).host | |
if current_host.respond_to? :should | |
current_host.should_not match /^#{subdomain}/ | |
else | |
assert_no_match /^#{subdomain}/, current_host | |
end | |
end | |
Then /^(?:|I )should land on the standard subdomain$/ do | |
current_host = URI.parse(current_url).host | |
domain_regex = (SubdomainFu.preferred_mirror.blank?) ? /^#{get_base_url}$/ : /^#{SubdomainFu.preferred_mirror}/ | |
if current_host.respond_to? :should | |
current_host.should match domain_regex | |
else | |
assert_match domain_regex, current_host | |
end | |
end |
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
SITE_URL = "www.example.com" | |
# Make sure you reset your host at the start of each test! | |
Before do | |
host! SITE_URL | |
Capybara.default_host = host | |
end |
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
Feature: Subdomain checks | |
Scenario: Visiting a specific login page | |
Given I am not logged in | |
When I visit the login page for the subdomain "foo" | |
Then I should land on the subdomain "foo" | |
And I should be on the login page | |
# extra stuff here... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment