对于简单路由,RSpec控制器测试失败
这可能是一个非常基本的错误,但我仍在学习。 =)
我的routes.rb只包括
WebPortal::Application.routes.draw do resources :categories end
如果我理解正确,这应该(以及其他)地图/categories
到CategoriesController.index
。 这个控制器看起来像
class CategoriesController < ApplicationController def index end end
相应的视图文件存在,rails服务器可以很好地提供此页面。 但我的RSpec测试
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版,因为我在http://ruby.railstutorial.org/上使用了rails教程中的Gemfile。 切换到2.7版修复了我的问题。