[英]RSpec controller test fails for simple route
This is probably a very basic error, but I am still learing. 这可能是一个非常基本的错误,但我仍在学习。 =)
=)
My routes.rb consists only of 我的routes.rb仅包含
WebPortal::Application.routes.draw do
resources :categories
end
If I understand this correctly, this should (among others) map /categories
to CategoriesController.index
. 如果我正确理解这一点,这应该(除其他外)将
/categories
映射到CategoriesController.index
。 This controller looks like 这个控制器看起来像
class CategoriesController < ApplicationController
def index
end
end
The corresponding view file exists, and rails server serves this page fine. 相应的视图文件存在,并且Rails服务器可以很好地服务于此页面。 But my RSpec test
但是我的RSpec测试
describe CategoriesController do
describe "GET :index" do
it "should be succesful" do
get :index
response.should be_succes
end
end
end
fails with the message 失败并显示消息
Failure/Error: get :index
ActionController::RoutingError:
No route matches {:controller=>"categories"}
What am I doing wrong here? 我在这里做错了什么?
Edit: 编辑:
The command rake routes
gives 命令
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"}
I was using RSpec version 2.6.1 because I used the Gemfile from the rails tutorial at http://ruby.railstutorial.org/ . 我使用的是RSpec 2.6.1版,因为我使用了来自http://ruby.railstutorial.org/的rails教程中的Gemfile。 Switching to version 2.7 fixed my problem.
切换到2.7版解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.