RSpec控制器测试失败,简单路由
这可能是一个非常基本的错误,但我仍然是learing。 =)
This is probably a very basic error, but I am still learing. =)
我的routes.rb只包含
My routes.rb consists only of
WebPortal::Application.routes.draw do
resources :categories
end
正确地理解这一点,这应该(其他)映射 /类别
到 CategoriesController.index
。这个控制器看起来像
If I understand this correctly, this should (among others) map /categories
to CategoriesController.index
. This controller looks like
class CategoriesController < ApplicationController
def index
end
end
存在,并且rails服务器为此页面提供服务。但我的RSpec测试
The corresponding view file exists, and rails server serves this page fine. But my RSpec test
describe CategoriesController do
describe "GET :index" do
it "should be succesful" do
get :index
response.should be_succes
end
end
end
失败,并显示
Failure/Error: get :index
ActionController::RoutingError:
No route matches {:controller=>"categories"}
我在这里做错了什么?
编辑:
rake routes
给予
rake routes
categories GET /categories(.:format) {:action=>"index", :controller=>"categories"}
POST /categories(.:format) {:action=>"create", :controller=>"categories"}
new_category GET /categories/new(.:format) {:action=>"new", :controller=>"categories"}
edit_category GET /categories/:id/edit(.:format) {:action=>"edit", :controller=>"categories"}
category GET /categories/:id(.:format) {:action=>"show", :controller=>"categories"}
PUT /categories/:id(.:format) {:action=>"update", :controller=>"categories"}
DELETE /categories/:id(.:format) {:action=>"destroy", controller=>"categories"}
我使用的RSpec版本2.6.1,因为我使用Gem文件从rails教程在 http://ruby.railstutorial.org/ 。切换到版本2.7修复了我的问题。
I was using RSpec version 2.6.1 because I used the Gemfile from the rails tutorial at http://ruby.railstutorial.org/. Switching to version 2.7 fixed my problem.