require 'spec_helper' require 'lograge' require 'active_support/notifications' require 'active_support/core_ext/string' require 'active_support/log_subscriber' require 'action_controller/log_subscriber' require 'action_view/log_subscriber' describe Lograge do describe "when removing Rails' log subscribers" do after do ActionController::LogSubscriber.attach_to :action_controller ActionView::LogSubscriber.attach_to :action_view end it "should remove subscribers for controller events" do expect { Lograge.remove_existing_log_subscriptions }.to change { ActiveSupport::Notifications.notifier.listeners_for('process_action.action_controller') } end it "should remove subscribers for all events" do expect { Lograge.remove_existing_log_subscriptions }.to change { ActiveSupport::Notifications.notifier.listeners_for('render_template.action_view') } end it "shouldn't remove subscribers that aren't from Rails" do blk = -> {} ActiveSupport::Notifications.subscribe("process_action.action_controller", &blk) Lograge.remove_existing_log_subscriptions listeners = ActiveSupport::Notifications.notifier.listeners_for('process_action.action_controller') listeners.size.should > 0 end end end