Reputation: 873
Some part of the development of my project has been done.Our company asks me to write cucumber test cases for the developed code and for the henceforth development as well. The routes file have two subdomains for admin and hosts.Devise is also being used.
Now i installed cucumber and have written the first scenario for the first story when the non registerd user lands on the home page,enters a valid email and gets redirected to the next page..the page has no password field.
Scenario: Non registered user lands on beta home page.
Given: I am on the homepage
When: I enter valid email with "[email protected]".
Then: I should be redirected to request invitation page.
The problem is in my routes file, I have,
constraints :subdomain => ADMIN_SUBDOMAIN do
....
root :to => admin#index
end
constraints :subdomain => HOST do
...
root :to => home#index.
end
Now how do i specify the path.rb file to look for the root_path in that specific subdomain. Theres no root_path written outside the subdomain constraints. This is my first time with testing. I am really stuck onto this.Any help is deeply appreciated.
I just got to know from somebody that this can be implemented using capybara.If so ,could you please give a little idea about it.
Upvotes: 3
Views: 1337
Reputation: 873
Turned out it was pretty simple.Capybara provides a default_host method. So I just needed to mention,
When I visit subomain sub
And then the webstep
Given /^I visit subdomain (.*)$/ do |site_domain|
site_domain = "http://sub.example.com" if site_domain == "admin"
Capybara.default_host = site_domain
visit "/"
end
Update:
default_host is not supposed to be used as it is not mentioned in the docs. Instead try using absolute path in visit.
Given /^I visit subdomain (.*)$/ do |site_domain|
site_domain = "http://sub.example.com" if site_domain == "admin"
visit site_domain
end
Upvotes: 6