Fu8*_*u86 0 testing unit-testing ruby-on-rails
我有以下代码
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
Run Code Online (Sandbox Code Playgroud)
如果我运行此rails功能测试
$ rake test:functionals
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
test_should_display_the_page_in_german(ApplicationControllerTest):
NameError: undefined local variable or method `request' for #<ApplicationControllerTest:0x1044c6d00>
Run Code Online (Sandbox Code Playgroud)
我如何访问"请求"变量?
@request.env["HTTP_REFERER"] = :index
Run Code Online (Sandbox Code Playgroud)
4.4可用的实例变量您还可以在功能测试中访问三个实例变量:
@controller – The controller processing the request
@request – The request
@response – The response
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2630 次 |
| 最近记录: |