English 中文(简体)
访问Sinatra测试响应中的管理员登录信息
原标题:Accessing warden login information in Sinatra test response

实际上,我所寻找的一切都在标题中说了——我需要在测试中访问管理员用户变量,以检查身份验证是否有效。另一种方法对我来说也是可能的,只是尝试很好地测试身份验证:)

should "authenticate" do
    post "/login", {:login => "test_login", :password => "password"}, {"HTTP_HOST" => "test.host"}
    assert last_response.redirect?
    assert_equal last_response.env["warden"].user.login, "test_login"
end
问题回答

在机架测试风格的全栈测试中,您无法进入内部请求环境。如果你想验证你是否以特定用户的身份登录,你需要查看重定向URL(如果它重定向到用户可识别的URL)或遵循重定向(使用rack-testsfollow_redirect!helper很容易),然后在HTML中查找用户ID的证据。

我本以为您不需要测试Warden本身,但您需要确保为其提供了正确的信息,并且不会在中间件堆栈中对其进行破坏。

您可能会发现类似黄瓜方便进行真正的表格填写和提交。

最后,Warden有自己的测试助手(肯定可以与机架测试配合使用),因此您可以设置登录请求,而无需在每个测试中实际运行登录请求/重定向周期-https://github.com/hassox/warden/wiki/testing有更多详细信息。





相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签