没有路由匹配 rspec 的匿名控制器 [英] No route matches rspec's anonymous controller

查看:37
本文介绍了没有路由匹配 rspec 的匿名控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于我对 rspec 规范的理解,我希望下面的例子通过.

Based on my understanding of the rspec spec, I would expect the following example to pass.

describe ApplicationController do

  controller do
    def test
    end
  end

  it "calls actions" do
    get :test
  end

end

相反,它失败了:

No route matches {:controller=>"anonymous", :action=>"test"}

我什至尝试在路由文件中为匿名"控制器定义路由,但无济于事.有什么我在这里想念的吗?这应该有效,不是吗?

I've even tried defining the route for the "anonymous" controller in the routes file but to no avail. Is there something I'm missing here? This should work, shouldn't it?

推荐答案

我遇到了类似的问题.就我而言,解决方案是在测试的 get 请求中包含一个 :id 参数.

I was having a similar problem. In my case the solution was including an :id parameter in the get request in the test.

get :test, :id => 1

检查您的路由,看看您是否缺少某个参数(可能是 :id),然后将其添加到测试中.

Check your routes and see if you are missing a certain parameter (probably :id), then add that to the test.

这篇关于没有路由匹配 rspec 的匿名控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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