Sha256: 37e7e4ab2f2a7c0e973b19735c2bff4ee7d74c6d2fc4dfe7727103045d251482

Contents?: true

Size: 957 Bytes

Versions: 6

Compression:

Stored size: 957 Bytes

Contents

describe BubbleWrap::Reactor::Eventable do
  before do
    @subject = Class.new do
      include BubbleWrap::Reactor::Eventable
    end.new
    @proxy = Class.new do 
      attr_accessor :proof
    end.new
  end

  describe '.on' do
    it 'registers events' do
      proof = proc {  }
      @subject.on(:foo, &proof)
      events = @subject.instance_variable_get(:@events)
      events[:foo].member?(proof).should == true
    end
  end

  describe '.trigger' do
    it 'calls event procs' do
      @proxy.proof = false
      @subject.on(:foo) do |r|
        @proxy.proof = r
      end
      @subject.trigger(:foo, true)
      @proxy.proof.should == true
    end

    it 'calls all the event procs' do
      @proxy.proof = 0
      @subject.on(:foo) { |r| @proxy.proof += r }
      @subject.on(:foo) { |r| @proxy.proof += r }
      @subject.on(:foo) { |r| @proxy.proof += r }
      @subject.trigger(:foo, 2)
      @proxy.proof.should == 6
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bubble-wrap-1.1.5 spec/motion/reactor/eventable_spec.rb
bubble-wrap-1.1.4 spec/motion/reactor/eventable_spec.rb
bubble-wrap-1.1.3 spec/motion/reactor/eventable_spec.rb
bubble-wrap-1.1.2 spec/motion/reactor/eventable_spec.rb
bubble-wrap-1.1.1 spec/motion/reactor/eventable_spec.rb
bubble-wrap-1.1.0 spec/motion/reactor/eventable_spec.rb