Sha256: edeefb814947fba9c1f16b3a41fcc274ef1416afd4cbeab9269c7f334f90419c

Contents?: true

Size: 1.75 KB

Versions: 55

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

describe Volt::Dependency do
  it 'should trigger on_dep and on_stop_dep when setup and torn down' do
    dep_count = 0
    stop_dep_count = 0
    dep = Volt::Dependency.new(-> { dep_count += 1 }, -> { stop_dep_count += 1 })

    expect(dep_count).to eq(0)
    expect(stop_dep_count).to eq(0)

    a = -> { dep.depend }.watch!
    b = -> { dep.depend }.watch!

    expect(dep_count).to eq(1)
    expect(stop_dep_count).to eq(0)

    a.stop
    expect(dep_count).to eq(1)
    expect(stop_dep_count).to eq(0)

    b.stop
    expect(dep_count).to eq(1)
    expect(stop_dep_count).to eq(1)

    # Make sure it triggers if we watch again
    c = -> { dep.depend }.watch!
    d = -> { dep.depend }.watch!

    expect(dep_count).to eq(2)
    expect(stop_dep_count).to eq(1)

    c.stop
    expect(dep_count).to eq(2)
    expect(stop_dep_count).to eq(1)

    d.stop
    expect(dep_count).to eq(2)
    expect(stop_dep_count).to eq(2)
  end

  it 'should trigger on_dep and on_stop_dep when changed and setup again' do
    dep_count = 0
    stop_dep_count = 0
    dep = Volt::Dependency.new(-> { dep_count += 1 }, -> { stop_dep_count += 1 })

    expect(dep_count).to eq(0)
    expect(stop_dep_count).to eq(0)

    a = -> { dep.depend }.watch!
    b = -> { dep.depend }.watch!

    expect(dep_count).to eq(1)
    expect(stop_dep_count).to eq(0)

    dep.changed!
    expect(dep_count).to eq(1)
    expect(stop_dep_count).to eq(1)

    # Make sure it triggers if we watch again
    c = -> { dep.depend }.watch!
    d = -> { dep.depend }.watch!

    expect(dep_count).to eq(2)
    expect(stop_dep_count).to eq(1)

    c.stop
    expect(dep_count).to eq(2)
    expect(stop_dep_count).to eq(1)

    d.stop
    expect(dep_count).to eq(2)
    expect(stop_dep_count).to eq(2)
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
volt-0.9.7.pre8 spec/reactive/dependency_spec.rb
volt-0.9.7.pre7 spec/reactive/dependency_spec.rb
volt-0.9.7.pre6 spec/reactive/dependency_spec.rb
volt-0.9.7.pre5 spec/reactive/dependency_spec.rb
volt-0.9.7.pre3 spec/reactive/dependency_spec.rb
volt-0.9.7.pre2 spec/reactive/dependency_spec.rb
volt-0.9.6 spec/reactive/dependency_spec.rb
volt-0.9.6.pre3 spec/reactive/dependency_spec.rb
volt-0.9.6.pre2 spec/reactive/dependency_spec.rb
volt-0.9.6.pre1 spec/reactive/dependency_spec.rb
volt-0.9.5 spec/reactive/dependency_spec.rb
volt-0.9.5.pre12 spec/reactive/dependency_spec.rb
volt-0.9.5.pre11 spec/reactive/dependency_spec.rb
volt-0.9.5.pre9 spec/reactive/dependency_spec.rb
volt-0.9.5.pre8 spec/reactive/dependency_spec.rb
volt-0.9.5.pre7 spec/reactive/dependency_spec.rb
volt-0.9.5.pre6 spec/reactive/dependency_spec.rb
volt-0.9.5.pre5 spec/reactive/dependency_spec.rb
volt-0.9.5.pre4 spec/reactive/dependency_spec.rb
volt-0.9.5.pre3 spec/reactive/dependency_spec.rb