2017-06-20 73 views
0

我有一个路线:Rspec的无路线控制器的规格相匹配

scope '/account' do 
    get '/' => 'accounts#index', as: :account 
end 

而且我想使用RSpec来测试它:

describe AccountsController, type: :controller do 
    it 'renders the index template' do 
    get :index 
    expect(response.status).to eq(200) 
    expect(response).to render_template :index 
    end 
end 

但我有:

ActionController::UrlGenerationError: No route matches

如何解决它?

完整的跟踪:

[11] pry(#<RSpec::ExampleGroups::AccountsController>)> get :index 
ActionController::UrlGenerationError: No route matches {:action=>"index", :controller=>"accounts"} 
from /home/rubydev/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.5/lib/action_dispatch/journey/formatter.rb:46:in `generate' 
+0

请分享错误跟踪跟踪? –

+0

@NarasimhaReddy更新 – Sts

+0

你能否提供整个测试文件,我测试了你的代码,它的工作原理,Rails,Ruby和RSpec版本? –

回答

0

你可以得到它通过改变路线的工作:虽然

scope '/accounts' do 
    get '/' => 'accounts#index', as: :account 
end 

林好奇,如果Account是一种资源,你为什么不声明帐户作为资源:

resource :accounts, :only => [:show, :index] 
+0

@Mohit这是一个遗留代码,我只是支持它 – Sts

+0

你尝试在范围中使用''/ accounts''吗? – moyinho20

+0

为什么我应该试试? – Sts

相关问题