Sha256: 11cac21bc9071bdc8efa67cda91d1bc6bed04cf151eec1e00ccbdf155bd2d019

Contents?: true

Size: 987 Bytes

Versions: 17

Compression:

Stored size: 987 Bytes

Contents

require 'spec_helper'
require 'volt/reactive/eventable'

class TestEventable
  include Volt::Eventable

  def trigger_works_event!
    trigger!('works', 20)
  end
end

describe Volt::Eventable do
  it 'should allow events to be bound with on' do
    test_eventable = TestEventable.new

    count = 0
    test_eventable.on('works') do |val|
      count += 1
      expect(val).to eq(20)
    end

    expect(count).to eq(0)
    test_eventable.trigger_works_event!
    expect(count).to eq(1)
  end

  it 'should allow events to be removed with .remove' do
    test_eventable = TestEventable.new

    count = 0
    listener = test_eventable.on('works') do
      count += 1
    end

    expect(listener.class).to eq(Volt::Listener)

    expect(count).to eq(0)
    test_eventable.trigger_works_event!
    expect(count).to eq(1)

    test_eventable.trigger_works_event!
    expect(count).to eq(2)

    listener.remove
    test_eventable.trigger_works_event!
    expect(count).to eq(2)
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
volt-0.8.27.beta3 spec/reactive/eventable_spec.rb
volt-0.8.27.beta2 spec/reactive/eventable_spec.rb
volt-0.8.27.beta1 spec/reactive/eventable_spec.rb
volt-0.8.26.beta1 spec/reactive/eventable_spec.rb
volt-0.8.26 spec/reactive/eventable_spec.rb
volt-0.8.24 spec/reactive/eventable_spec.rb
volt-0.8.23 spec/reactive/eventable_spec.rb
volt-0.8.22 spec/reactive/eventable_spec.rb
volt-0.8.22.beta2 spec/reactive/eventable_spec.rb
volt-0.8.22.beta1 spec/reactive/eventable_spec.rb
volt-0.8.21 spec/reactive/eventable_spec.rb
volt-0.8.20 spec/reactive/eventable_spec.rb
volt-0.8.19 spec/reactive/eventable_spec.rb
volt-0.8.18 spec/reactive/eventable_spec.rb
volt-0.8.17 spec/reactive/eventable_spec.rb
volt-0.8.16 spec/reactive/eventable_spec.rb
volt-0.8.15 spec/reactive/eventable_spec.rb