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语法或类似的东西?