0
我有這樣的測試:RSpec的「無路由匹配」錯誤,但它們匹配
RSpec.describe RestaursController, :type => :controller do
context "GET /restaurs/:id" do
before do
@rest = FactoryGirl.create :restaur
end
context "resource exists" do
subject { get "restaurs/#{@rest.id}"}
it { expect(subject).to render_template(:show) }
end
context "resource doesn't exists" do
subject { get "restaurs/#{@rest.id + 1}" }
it { expect(subject).to redirect_to(:root) }
end
end
end
當我運行這些測試RSpec的說:
Failure/Error: subject { get "restaurs/#{@rest.id}"}
ActionController::UrlGenerationError:
No route matches {:action=>"restaurs/7", :controller=>"restaurs"}
但我認爲我的路線是確定。看看rake routes
日誌
Prefix Verb URI Pattern Controller#Action
restaurs GET /restaurs(.:format) restaurs#index
POST /restaurs(.:format) restaurs#create
new_restaur GET /restaurs/new(.:format) restaurs#new
edit_restaur GET /restaurs/:id/edit(.:format) restaurs#edit
restaur GET /restaurs/:id(.:format) restaurs#show
PATCH /restaurs/:id(.:format) restaurs#update
PUT /restaurs/:id(.:format) restaurs#update
DELETE /restaurs/:id(.:format) restaurs#destroy
root GET / restaurs#index
你有什麼想法嗎?問題是什麼?也許這是關於RSpec語法或類似的東西?