For a controller that determines the behaviour of a sidebar, I need to call several urls; the sidebar will change (a.o) based on the page on which it appears.
describe SidebarController do
before(:each) do
@sidebar = SidebarController.new
end
it 'should return :jobseekers for root_path' do
get(root_url)
@sidebar.section(root_path).should eq :jobseekers
end
end
This, however, fails with ActionController::RoutingError: No route matches {:controller=>"sidebar", :action=>"http://test.host/"}
Can I get
an url or path as string? Is there a smarter way to set the request.
data, rather then GETting it?
Can I get an url or path as string?
Not in a controller test. The test controller is not actually processing a URL, it is setting up the test using one of the 5 supporting request types (get, post, put, head, delete) and then calling the appropriate controller action. See the Guide to Testing Rails Applications.
What you are looking for is an integration test, or a "request spec" in RSpec terms.
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