Stubbing Warden on Controller Tests

后端 未结 2 1241
甜味超标
甜味超标 2021-01-14 01:16

I\'m having an issue with testing my controllers and using Warden.

All examples point at stubbing request.env[\'warden\']. This causes issues in my cont

2条回答
  •  一整个雨季
    2021-01-14 01:26

    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.

提交回复
热议问题