【发布时间】:2014-10-08 03:38:49
【问题描述】:
我正在尝试基于this example动态创建一个控制器来测试我的rails控制器问题。
我的代码是这样的
require 'test_helper'
class RequireAuthenticationTest < ActionController::TestCase
test "Throws token required error" do
@controller = RequireAuthenticationTestController.new(:index) { require_authentication; render :nothing => true }
get :index
assert_response :success
end
end
class RequireAuthenticationTestController < ActionController::Base
include RequireAuthentication
def initialize(method_name, &method_body)
self.class.send(:define_method, method_name, method_body)
end
end
然而,每当我尝试运行代码时,我都会收到错误消息
RequireAuthenticationTest#test_Throws_token_required_error: ActionController::UrlGenerationError:没有路由匹配 {:action=>"index", :controller=>"require_authentication_test"} test/controllers/concerns/require_authentication_test.rb:7:in `block in '
关于我做错了什么有什么建议吗?谢谢!
【问题讨论】:
-
您也可以发布您的 RequireAuthentication 代码吗?
-
我认为这无关紧要。问题是控制器路由没有被识别。我的 RequireAuthentication 代码甚至没有被调用。
-
哼。我在尝试运行博客文章中的代码时遇到错误。你用的是哪个版本的 Rails 和 mini test?
-
Rails 4.1.6 和 Minitest 5.4.2
-
你最终弄明白了吗?如果是这样,你会这么好心回答你自己的问题。我现在正在查看确切的一些问题。
标签: ruby-on-rails ruby ruby-on-rails-4 minitest