How do I disable cache sweepers for testing purposes
-
11-01-2021 - |
Frage
I'm using a sweeper to watch a model and do some logging with snogmetrics:
class UserSweeper < ActionController::Caching::Sweeper
observe User
def after_create(user)
km.identify(user.email)
end
end
I'm doing this with a sweeper instead of an observer because snogmetrics needs the session in order to function properly.
However, while testing, snogmetrics utterly fails
NoMethodError: undefined method `identify' for nil:NilClass
How can I disable the sweeper for unit tests? Thanks!
Lösung 2
I was able to use the no-peeping-toms gem to block observers during testing.
NOTE: This also works for rake tasks. I had an issue with observers being called during a migration and this solved it.
Andere Tipps
Where is km
defined? From what I see, it's not defined in your user_sweeper so it will fail regardless the environment you're in.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow