Sha256: c865c83dcc993dce1431dee3dc59b751fd00cbd194dd77afea9777d454c907d4
Contents?: true
Size: 1.56 KB
Versions: 3
Compression:
Stored size: 1.56 KB
Contents
module Boty RSpec.describe Boty::Eventable do class Client include Eventable end subject(:eventable) { Client.new } describe "#on" do it "binds an event `'type'` to a block" do expect { |b| eventable.on :omg, &b eventable.event "type" => "omg", "other_field" => "lol" }.to yield_with_args "type" => "omg", "other_field" => "lol" end end describe "#off" do let(:data) do { "type" => "bbq", "text" => "omg. wtf." } end it "unbounds an event by type AND block, just if the block is the same" do @permanent_executed = false permanent_block = ->(_) do @permanent_executed = true end eventable.on :bbq, &permanent_block @ephemeral_executed = false ephemeral_block = ->(_) do @ephemeral_executed = true end eventable.on :bbq, &ephemeral_block eventable.off :bbq, &ephemeral_block eventable.event data expect(@permanent_executed).to eq true expect(@ephemeral_executed).to eq false end it "unbounds all events by type" do @first_block = @second_block = @third_block = false eventable.on(:bbq) do |_| @first_block = true end eventable.on(:bbq) do |_| @second_block = true end eventable.on(:bbq) do |_| @third_block = true end eventable.off(:bbq) eventable.event data expect(@first_block).to eq false expect(@second_block).to eq false expect(@third_block).to eq false end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
boty-1.0.1 | spec/boty/eventable_spec.rb |
boty-1.0.0 | spec/boty/eventable_spec.rb |
boty-0.2.0 | spec/boty/eventable_spec.rb |