繁体   English   中英

ActionController :: TestCase的方法get忽略route.rb?

[英]Method get of ActionController::TestCase ignores routes.rb?

我遇到了问题,似乎表明ActionController :: TestCase.get()方法忽略了route.rb中的内容。

Rails版本是3.0.10。

我的XmlRpcController#index操作具有以下RSpec2测试:

it "should get nothing in response to GET request" do
  get :index
  response.response_code.should == 400 #bad_request
end

而在routes.rb中与此路由相关的唯一一行是:

post 'rpc', :to => "xml_rpc#index"

“耙线路线”也仅显示定义的该路线。

结果,当我运行此测试时,实际上确实执行了该操作! 我通过在其中放一个简单的puts来判断),并且还包含一个日志:

由XmlRpcController#index处理为HTML

另外,如果我在浏览器中转到“ localhost:3000 / rpc”,则会显示找不到路由:就像应该这样。 但是测试还有其他行为,这让我感到困惑。

有人可以暗示我为什么会这样吗? 我只是开始学习RoR :)在我看来,TestCase的这些“获取/发布”方法确实尊重route.rb。

我是否缺少明显的东西? :)

似乎“ get:index”方法确实忽略了routes.rb。

对我来说,真正的解决方案是使用为此目的而编写的be_routable rspec匹配器:

  describe "GET 'contact'" do
    it "should be successful" do
      { :get => '/rpc' }.should_not be_routable
    end
  end

感谢Ruby-Forum的一些用户来解决这个问题。 更多信息在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM