【问题标题】:How to write RefineryCMS controller tests without RoutingError如何编写没有 RoutingError 的 RefineryCMS 控制器测试
【发布时间】:2012-10-30 16:52:26
【问题描述】:

这样的 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,它们也因路由错误而失败。我当然想为我自己添加到香草炼油厂控制器的额外方法编写测试,但我只是想看看我是否可以让控制器测试为全新的炼油厂安装工作。

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

【问题讨论】:

    标签: ruby-on-rails-3 rspec2 refinerycms


    【解决方案1】:

    我偶然发现了这个。而不是:

    get :wymiframe
    

    我需要使用:

    get :wymiframe, { use_route: :any_old_thing }
    

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

    【讨论】:

    • 升级到 RefineryCMS 2.1 后,我仍在为此苦苦挣扎 - 这又使这个问题再次出现,我的旧“技巧”并不总是有效(但有时仍然有效......)。我认为这与引擎和他们自己的路线有关,但不确定
    • 升级到 RefineryCMS 2.1 后,我不得不再次为此苦苦挣扎。我仍然不知道它为什么起作用(但并非总是如此)。最后,我通过从 core/support/refinery.rb 中放置一些 refinerycms 自己的配置解决了我的问题(因此不需要奇怪的 hack)。这些似乎使控制器规范可以访问必要的路由。
    猜你喜欢
    • 1970-01-01
    • 2011-10-05
    • 2023-03-16
    • 2011-10-03
    • 1970-01-01
    • 1970-01-01
    • 2015-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多