spec/ventable/ventable_spec.rb in ventable-0.0.5 vs spec/ventable/ventable_spec.rb in ventable-0.0.6

- old
+ new

@@ -5,10 +5,29 @@ class TestEvent include Ventable::Event end end + describe '::enabled?' do + after { Ventable.enable } + + it 'is true by default' do + expect(Ventable.enabled?).to be_true + end + + it 'is false after Ventable is disabled' do + Ventable.disable + expect(Ventable.enabled?).to be_false + end + + it 'is true after Ventable is re-enabled' do + Ventable.disable + Ventable.enable + expect(Ventable.enabled?).to be_true + end + end + describe "including Ventable::Event" do it "should create a class instance variable to keep observers" do TestEvent.observers.should_not be_nil TestEvent.observers.should be_a(Set) end @@ -110,9 +129,25 @@ transaction_called.should be_true transaction_already_completed.should be_false event_inside.should_not be_nil event_inside.should be_a(TestEvent) + end + + context 'when globally disabled' do + before { Ventable.disable } + after { Ventable.enable } + + it 'does not notify observers' do + observers_notified = false + + TestEvent.notifies do |event| + observers_notified = true + end + + TestEvent.new.fire! + expect(observers_notified).to be_false + end end end describe "#default_callback_method" do before do