Stubbing Warden on Controller Tests

倖福魔咒の 提交于 2019-12-01 06:48:42

I wrote controller test helpers for Warden.

http://kentaroimai.com/articles/1-controller-test-helpers-for-warden

Despite many examples telling you to implement Warden through env['warden'] in your Rails app. It seems the correct way to access it through request.env['warden'].

It found this out by raising env in my controllers during tests, and this always came out nil.

It seems in Warden, https://github.com/hassox/warden/blob/master/lib/warden/proxy.rb#L13 There is an accessor for the rack environment, which won't exist in test mode due to the absence of Rack in controller tests. Please someone check this.

So when stubbing request.env in RSpec, your implementation needs to point at request.env.

It seems a necessary evil in my mind. But if there is anyone with a good explanation or work around, I'd love to continue this discussion.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!