【问题标题】:What is the "path"variable in rails integration test?Rails集成测试中的“路径”变量是什么?
【发布时间】:2015-11-22 05:16:14
【问题描述】:

我在查看 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

我对@9​​87654322@ 行中的变量“路径”感到困惑。这究竟是什么?这是我们在它之前执行post_via_redirect 操作后将显示在您的浏览器中的网址吗?

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

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

【问题讨论】:

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


    【解决方案1】:

    path 是您当前页面的网址。

    pathrequest.url,没有域名。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-01
      相关资源
      最近更新 更多