2
我测试这样我轨辅助方法:测试辅助方法Rails中
require File.dirname(__FILE__) + '/../../test_helper'
require 'action_view/test_case'
require 'action_view/helpers'
class ListingsHelperTest < ActionView::TestCase
def setup
@controller = ListingsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
end
这个伟大的工程,除非该调用助手在需要的请求已经发生的方法,如url_for 。由于我不想通过请求过程来运行整个堆栈以测试这些堆栈(例如,通过调用get:index),因此需要初始化或删除这些内容才能起作用?
我正在寻找一个更通用的解决方案,以嘲笑的请求,但具体而言,我得到的错误是这样的:
NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.rewrite
rails/actionpack/lib/action_controller/base.rb:625
rails/actionpack/lib/action_view/helpers/url_helper.rb:85
rails/actionpack/lib/action_view/helpers/url_helper.rb:85
这是门票,谢谢!我也刚刚意识到这种技术可能会在rails自己的帮助程序测试中可见,对吗? – 2009-02-22 01:35:23