spec/flirt/flirt_spec.rb in flirt-0.0.4 vs spec/flirt/flirt_spec.rb in flirt-0.1.0

- old
+ new

@@ -48,9 +48,129 @@ end end + describe "then more listeners added" do + + let(:event2) { :topping_added } + + let(:event3) { :plated_up } + + let(:callback2) { :respond2 } + + let(:callback3) { :respond3 } + + before(:each) do + Flirt.subscribe listener, event2, with: callback2 + + Flirt.subscribe listener, event3, with: callback3 + end + + after(:each) { Flirt.enable } + + describe "when a single event is disabled" do + + it "disables just that event" do + Flirt.disable only: :pancake_fried + expect(listener).not_to receive(callback) + expect(listener).to receive(callback2).with(response) + expect(listener).to receive(callback3).with(response) + Flirt.publish event, response + Flirt.publish event2, response + Flirt.publish event3, response + end + + end + + describe "when multiple events are disabled" do + + before(:each) { Flirt.disable only: [:pancake_fried, :topping_added] } + + it "disables those events" do + expect(listener).not_to receive(callback) + expect(listener).not_to receive(callback2) + expect(listener).to receive(callback3).with(response) + Flirt.publish event, response + Flirt.publish event2, response + Flirt.publish event3, response + end + + it "forgets those events after a call to #enable" do + Flirt.enable + expect(listener).to receive(callback) + expect(listener).to receive(callback2).with(response) + expect(listener).to receive(callback3).with(response) + Flirt.publish event, response + Flirt.publish event2, response + Flirt.publish event3, response + end + + + it "forgets those events after a call to #disable" do + Flirt.disable + expect(listener).not_to receive(callback) + expect(listener).not_to receive(callback2).with(response) + expect(listener).not_to receive(callback3).with(response) + Flirt.publish event, response + Flirt.publish event2, response + Flirt.publish event3, response + end + end + + describe "when a single event is enabled" do + + it "enables just that event" do + Flirt.enable only: :pancake_fried + expect(listener).to receive(callback) + expect(listener).not_to receive(callback2).with(response) + expect(listener).not_to receive(callback3).with(response) + Flirt.publish event, response + Flirt.publish event2, response + Flirt.publish event3, response + end + + end + + + describe "when multiple events are enabled" do + + before(:each) { Flirt.enable only: [:pancake_fried, :topping_added] } + it "enables those events" do + Flirt.enable only: [:pancake_fried, :topping_added] + expect(listener). to receive(callback) + expect(listener). to receive(callback2).with(response) + expect(listener).not_to receive(callback3).with(response) + Flirt.publish event, response + Flirt.publish event2, response + Flirt.publish event3, response + end + + + it "forgets those events after a call to #enable" do + Flirt.enable + expect(listener).to receive(callback) + expect(listener).to receive(callback2).with(response) + expect(listener).to receive(callback3).with(response) + Flirt.publish event, response + Flirt.publish event2, response + Flirt.publish event3, response + end + + + it "forgets those events after a call to #disable" do + Flirt.disable + expect(listener).not_to receive(callback) + expect(listener).not_to receive(callback2).with(response) + expect(listener).not_to receive(callback3).with(response) + Flirt.publish event, response + Flirt.publish event2, response + Flirt.publish event3, response + end + end + end + + describe "when cleared" do let(:callback2) { :respond2 } \ No newline at end of file