开发者

Access the "request" variable on Rails controller tests

开发者 https://www.devze.com 2023-01-13 15:36 出处:网络
I have the following code require \'test_helper\' class Applic开发者_开发技巧ationControllerTest < ActionController::TestCase

I have the following code

require 'test_helper'

class Applic开发者_开发技巧ationControllerTest < ActionController::TestCase
  test "should display the page in german" do
    get :index
    assert_response :success
    # ...
    request.env["HTTP_REFERER"] = :index
    # ...
  end
end

If I run this rails functional test with

$ rake test:functionals

I get this error:

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

How can i Access the "request" variable?


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

Testing Guide

4.4 Instance Variables Available You also have access to three instance variables in your functional tests:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号