rails集成测试中的“路径”变量是什么?

时间:2015-11-22 05:16:15

标签: ruby-on-rails unit-testing integration-testing

我正在查看RailsGuides,我看到了这个例子:

require 'test_helper'

class UserFlowsTest < ActionDispatch::IntegrationTest
  test "login and browse site" do
    # login via https
    https!
    get "/login"
    assert_response :success

    post_via_redirect "/login", username: users(:david).username, password: users(:david).password
    assert_equal '/welcome', path
    assert_equal 'Welcome david!', flash[:notice]

    https!(false)
    get "/articles/all"
    assert_response :success
    assert assigns(:articles)
  end
end

我对行assert_equal '/welcome', path中的变量“path”感到困惑。这究竟是什么?这是我们在之前执行post_via_redirect操作后会在您的浏览器中显示的网址吗?

我查看了集成测试中可用的帮助程序,但该文档没有说明这个“路径”变量。

此外,我在我的rails应用程序中尝试它并且它工作正常,但是当我尝试在我的一个控制器测试中调用它时,它给了我undefined local variables or method错误。那么它是否意味着“path”变量仅在集成测试中可用?如果我想在其他类型的测试中使用它会怎么样?

1 个答案:

答案 0 :(得分:0)

path是您当前页面的网址。

pathrequest.url,没有域名。

在此测试中,您已从'/ login'重定向到'/ welcome'。