I am getting no route matches error when I test a view which uses #url_for. My application runs fine when I load the view but rspec tests can't find the route. I don't want to mock #url_for.
Is there a way to make this work without mocking? Thanks in advance.
1) shared/menu when auth is disabled displays
Failure/Error: render template: 'shared/_menu'
ActionView::Template::Error:
No route matches {:action=>"index", :controller=>"gadgets"}
# /Users/tc/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.4/lib/action_dispatch/journey/formatter.rb:46:in `generate'
# /Users/tc/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:729:in `generate'
# /Users/tc/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:760:in `generate'
# /Users/tc/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:803:in `url_for'
# /Users/tc/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.4/lib/action_dispatch/routing/url_for.rb:156:in `url_for'
# /Users/tc/.rvm/gems/ruby-2.2.3/gems/actionview-4.2.4/lib/action_view/routing_url_for.rb:94:in `url_for'
--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/884080c5-7dc2-4e89-b3d8-7dfa7916a586%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
resources :users, only: [:index, :show] do resources :gadgets, only: [:index, :show]
endTo view this discussion on the web visit https://groups.google.com/d/msgid/rspec/79ddc31c-2060-4134-8e71-09a83aa358b9%40googlegroups.com.
Prefix Verb URI Pattern Controller#Action
user_gadgets GET /users/:user_id/gadgets(.:format) gadgets#index
user_gadget GET /users/:user_id/gadgets/:id(.:format) gadgets#show
allow(view).to receive(:params).and_return(user_id: 'test-id', id: 'id_1')
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/bfca9f42-3a68-4bc3-9432-1c963d57e96a%40googlegroups.com.
navs << { active: true text: 'View', href: url_for(controller: 'gadgets, action: :index), }require 'spec_helper'
RSpec.describe '/shared/nav', type: :view do
before do allow(view).to receive(:params).and_return(user_id: 'test-id', id: 'id_1') render template: 'shared/_menu' end
context 'when set' do it 'works' do end endend navs << { active: true text: 'View', href: url_for(controller: 'gadgets', action: :index), }To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/8731c42c-c6d1-4ea3-b718-dd9b4c37973b%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/1184333c-6721-4349-8399-0d329bdcd869%40googlegroups.com.