I'm using observers in my Rails app for notifications, activity feeds, etc. They keep my models and controllers clean, work great on the app side, and in any non-integration test (I've unit tested them extensively/successfully). But I can't for the life of me get them working in integration tests. I have the following in spec/support/observers.rb (as a sanity check. I'd ideally only enable them for feature tests if I can get them to work at all):
RSpec.configure do |config|
config.before do
ActiveRecord::Base.observers.enable :all
end
end
No matter what I do, I can't get my observers to fire off during my integration tests (which is exactly what I really want to use to ensure that everything is truly working).
Does anyone have any insight on this or have any clue as to why I could be experiencing this? I'm using Rails 5.0.0beta3, and the latest versions of rails-observers, rspec-rails and capybara (from github master branches).
This isn't truly an answer to my question, but ain't nobody got time to wait around. No one cares about observers anymore because they were removed form Rails 4. There are next to no google topics related to them and capybara.
So, in order move on and get integration test coverage on the code I need, I'm refactoring my code to use concerns that include callbacks. This eliminates the observer dependency, and I was actually able to abstract my code even further this way since many of my observers were doing pretty much the same thing, and I had the core of what my observers were calling in service objects anyway.
Integration tests have no problem triggering these.
RIP Observers.