从完成成功测试 redirect_to(:back) 不起作用

Testing a redirect_to(:back) on successful from completion isn't working

我正在尝试 运行 一项在成功完成表单时具有 redirect_to(:back) 的测试,当我 运行 这一行

时出现此错误
assert_difference 'Comment.count', 1 do
      post comments_path, comment: { body:  "OPTC", commentable_id: 1, commentable_type: 'Post'}
end

错误 ActionController::RedirectBackError: No HTTP_REFERER was set in the request to this action, so redirect_to :back could not be called successfully. If this is a test, make sure to specify request.env["HTTP_REFERER"].

Looking into this 我知道我需要在设置中添加类似 request.env['HTTP_REFERER'] = 'http://test.com/' 的内容。但这只会给出错误 NoMethodError: undefined method 'env' for nil:NilClass

现在我不知道该怎么办。我怎样才能让第一个错误消失?

更新

我正在使用 rails 4

这里是测试文件的头部

需要'test_helper'

class CategoryItemShowPageTest < ActionDispatch::IntegrationTest

 def setup
    @user = users(:michael)
    @user1 = users(:archer)
    @guide = Guide.find(1)
    @category = Category.find(1)
    @category_item = CategoryItem.find(1)
    @mod_relationship = game_mods_relationships(:mod1)
    request.env['HTTP_REFERER'] = 'http://test.com/'

  end

正如上面评论中所讨论的,我相信,这应该可以在 Rails 4 集成测试中设置参数和 HTTP 引用:

post comments_path, 
     { comment: { body: "OPTC", commentable_id: 1, commentable_type: 'Post' } }, 
     { 'HTTP_REFERER' => 'http://www.somewhere.net' }