2017-06-20 4 views
0

Ich habe eine Route:Rspec Keine Route passt in Controller-Spezifikation

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

Und ich will es mit RSpec testen:

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 

Aber ich habe bekam:

ActionController::UrlGenerationError: No route matches

Wie man es repariert?

Die vollständige Spur:

[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

bitte teilen Fehler Spur verfolgen? –

+0

@NarasimhaReddy aktualisiert – Sts

+0

Können Sie die gesamte Testdatei zur Verfügung stellen, ich habe Ihren Code getestet und es funktioniert, welche Rails, Ruby und RSpec Version? –

Antwort

0

Sie können es, indem Routen an die Arbeit: obwohl

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

Im neugierig, wenn Account eine Ressource ist, warum würden Sie nicht ein erklären Konten als Ressource:

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

@Mohit es ist ein Legacy-Code Ich unterstütze es nur – Sts

+0

Haben Sie versucht, ''/ accounts'' im Bereich? – moyinho20

+0

warum sollte ich es versuchen? – Sts

Verwandte Themen