RSpec控制器测试失败,简单路由 [英] RSpec controller test fails for simple route

查看:183
本文介绍了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.

这篇关于RSpec控制器测试失败,简单路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆