使用 Minitest 和身份验证进行功能测试

发布于 2024-12-17 23:50:16 字数 192 浏览 6 评论 0原文

我正在尝试进行功能测试,但我不知道如何处理 cookie。 我正在使用 Ruby 和 Minitest 进行控制器的功能测试。 但要在控制器中运行测试,首先我需要进行身份验证。 身份验证使用 cookie 来查看用户是否已登录。 问题是功能测试看不到 cookie 中的内容,因此我无法进行身份验证然后运行测试。有人给我提示来解决这个问题吗?

谢谢 赫伯

I'm trying to do functional test but I don't know how to deal with cookies.
I'm using Ruby and Minitest to do functional test of controllers.
But to run tests in controllers, first I need to authenticate.
The authentication uses cookies to see if the user is logged or not.
The problem is functional tests do not see what is in cookies, than I can't authenticate and then run tests. Does someone give me a tip to resolve this?

thanks
Heber

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慵挽 2024-12-24 23:50:16

我自己也在看同样的问题。由于对此有些陌生,我实际上不确定这是否有效,但我打算尝试使用 before do 挂钩来运行身份验证。

有这样的效果:

    before do
      get :login
      # fill in and submit
    end

    it "must do stuff" do
      #Test things and hopefully it'll be logged in
    end

I'm looking at the same issue, myself. Being somewhat new at this, I'm not actually sure this will work, but I intend to try using the before do hook to run an authentication.

Something to this effect:

    before do
      get :login
      # fill in and submit
    end

    it "must do stuff" do
      #Test things and hopefully it'll be logged in
    end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文