gpt4 book ai didi

ruby-on-rails - 在 Rails Controller 测试中访问 "request"变量

转载 作者:行者123 更新时间:2023-11-28 21:01:14 25 4
gpt4 key购买 nike

我有以下代码

require 'test_helper'

class ApplicationControllerTest < ActionController::TestCase
test "should display the page in german" do
get :index
assert_response :success
# ...
request.env["HTTP_REFERER"] = :index
# ...
end
end

如果我运行这个 Rails 功能测试

$ rake test:functionals

我收到这个错误:

test_should_display_the_page_in_german(ApplicationControllerTest):
NameError: undefined local variable or method `request' for #<ApplicationControllerTest:0x1044c6d00>

如何访问“请求”变量?

最佳答案

@request.env["HTTP_REFERER"] = :index

Testing Guide

4.4 实例变量可用您还可以在功能测试中访问三个实例变量:

@controller – The controller processing the request
@request – The request
@response – The response

关于ruby-on-rails - 在 Rails Controller 测试中访问 "request"变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3565346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com