2

像这样的 Rspec 测试(实际上取自 RefineryCMS 自己的测试套件)

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

module Refinery
  describe FastController do
    it "should render the wymiframe template" do
      get :wymiframe
      response.should be_success
    end
  end
end

导致以下错误:

Failure/Error: get :wymiframe
ActionController::RoutingError:
  No route matches {:controller=>"refinery/fast", :action=>"wymiframe"}
# ./spec/controllers/fast_controller_spec.rb:6:in `block (2 levels) in <module:Refinery>'

在这种情况下,我将炼油厂 2.0.8 与 Rspec 2.11 一起使用,运行 rake 路由后的相关部分如下所示:

wymiframe GET     /wymiframe(/:id)(.:format)        refinery/fast#wymiframe

我尝试了其他一些控制器 Rspec,它们也因路由错误而失败。我当然正在尝试为我自己添加到香草炼油厂控制器的额外方法编写测试,但我只是想看看我是否可以让控制器测试为全新的炼油厂安装工作。

这一定是一个简单的错误!有什么建议么?

4

1 回答 1

1

我偶然发现了这一点。代替:

get :wymiframe

我需要使用:

get :wymiframe, { use_route: :any_old_thing }

我不知道为什么会这样——特别是因为对于“any_old_thing”,我真的没有使用任何有意义的或与我的项目相关的东西。但是,它似乎奏效了,现在我可以测试我的控制器了。

于 2012-10-30T08:52:26.960 回答