How do I use named routes in the Rails spec?
I have a Rails Engine with engine.rb installed:
module Keywords
class Engine < ::Rails::Engine
isolate_namespace Keywords
end
I have certain routes:
Keywords::Engine.routes.draw do
resources :keyword_groups, only: [:new]
end
Now everything works fine inside my dummy app. i can use a variable keywords.new_keyword_group_path
to get my path url.
However, when I try to do the same in my rspec tests using capybara, it fails! I tried to add the following line to my spec_helper.rb as suggested:
config.include Keywords::Engine.routes.url_helpers
But, when I try to use the following line in my tests:
visit keywords.new_keyword_group_path
I am getting the following error:
NameError: undefined local variable or method `keywords' for #<RSpec::Core::ExampleGroup::Nested_1:0x00000108833390>
If I instead try to leave the "keywords" prefix and do:
visit new_keyword_group_path
I am getting this error:
ActionController::RoutingError: No route matches [GET] "/keyword_groups/new"
which makes sense as the path should be "/ keywords / keyword_groups / new".
How can I get the included URL helpers to use the correct namespace prefix?
+3
source to share