2017-06-20 42 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