Trying to get Warden to work in Action specs

I’ve been dabbling with Hanami and enoying it but I’ve hit an issue I can’t seem to figure out. I’ve been following and adapting this post to implement Warden into Hanami and I’ve got it working in a way I’m pretty happy with but I can’t get action specs to work.

I would love some help as I feel the way the middleware has been injected is wrong for usage within Actions and should instead be used via Deps somehow.

The relevant files in my project:

  • app/actions/sessions/create.rb
  • spec/actions/sessions/create_spec.rb
  • config/app.rb
  • config/providers/warden.rb

The error I’m getting when running the test is that request.env[“warden”] is nil even if I do a hanami.boot.

Happy to answer any more questions to help and if this is posted in the wrong spot I’m sorry!

Hi Sean and welcome to the forum!

Action specs should generally just cover the logic inside the action. If you need middleware, you should probably use request specs (as it is in the linked blog post). At least that’s how I would approach this.

If you really want an action spec, I think you can pass the env to subject.call in tests (but I don’t have an example at hand of how to do that).

EDIT: I think we should definitely have an example of that in the docs.

1 Like

Thanks for taking the time to help, this has unstuck me!