steveklabnik / request_store

Per-request global storage for Rack.
https://github.com/steveklabnik/request_store
MIT License
1.47k stars 87 forks source link

Addition to support clearing RequestStore for Controller Specs #40

Closed justin808 closed 6 years ago

justin808 commented 9 years ago

In my conversion to using request_store, controller specs were depending on a before hook in the controllers to do the clear. I'd like to propose that I submit a PR that contains the following:

  1. Spec Helper to include that calls RequestStore.clear!:
module RequestStoreSupport
  # Override process to call clear, since that is done if Rack is available
  def process(*)
    RequestStore.clear!
    super
  end
end
  1. Update the README to suggest adding this line to spec_helper.rb or rails_helper.rb
  config.include RequestStoreSupport, type: :controller

This was modeled after the way Devise::TestHelpers is done.

If this sounds good, I'll create a PR. This solution seems to be working for me.

steveklabnik commented 9 years ago

I think this makes more sense as something like https://github.com/steveklabnik/request_store#no-rails--racktest than as code.

justin808 commented 9 years ago

@steveklabnik Are you confident that your approach would work for controller specs? And does my approach not get used for request and feature specs?