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!

有帮助吗?

解决方案 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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top