rspec - How do i use named routes in an Rails engine's specs? -


i have rails engine engine.rb defined:

module keywords   class engine < ::rails::engine     isolate_namespace keywords end 

i have routes defined:

keywords::engine.routes.draw   resources :keyword_groups,  only: [:new]  end 

now, works great inside dummy app. can use variable keywords.new_keyword_group_path url path.

however, when try same in rspec tests using capybara, fails! tried add following line spec_helper.rb suggested:

config.include keywords::engine.routes.url_helpers 

but, when try use following line in tests:

visit keywords.new_keyword_group_path 

i following error:

nameerror: undefined local variable or method `keywords' #<rspec::core::examplegroup::nested_1:0x00000108833390> 

if instead try leave off "keywords" prefix, , do:

visit new_keyword_group_path 

i error:

actioncontroller::routingerror: no route matches [get] "/keyword_groups/new" 

which makes sense path should "/keywords/keyword_groups/new".

how can included url helpers use correct namespace prefix?

i found solution based on spree gem. creating helper method prefix grab path engines routes so:

def keywords   keywords::engine.routes.url_helpers end 

then keywords.new_keyword_path works charm


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -