Sha256: 222358e2bd97ad88fa670f49a104c4ff76a1ff15372703b07defdc1a8032843c

Contents?: true

Size: 798 Bytes

Versions: 6

Compression:

Stored size: 798 Bytes

Contents

require 'promise'

describe 'Promise#trace' do
  it 'calls the block with all the previous results' do
    x = 42

    Promise.value(1).then { 2 }.then { 3 }.trace {|a, b, c|
      x = a + b + c
    }

    x.should == 6
  end

  it 'calls the then after the trace' do
    x = 42

    Promise.value(1).then { 2 }.then { 3 }.trace {|a, b, c|
      a + b + c
    }.then { |v| x = v }

    x.should == 6
  end

  it 'works after a when' do
    x = 42

    Promise.value(1).then {
      Promise.when Promise.value(2), Promise.value(3)
    }.trace {|a, b|
      x = a + b[0] + b[1]
    }

    x.should == 6
  end

  it 'raises an exception when the promise has already been chained' do
    p = Promise.value(2)
    p.then {}

    proc {
      p.trace {}
    }.should raise_error(ArgumentError)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
opal-0.7.2 spec/opal/stdlib/promise/trace_spec.rb
opal-0.7.1 spec/opal/stdlib/promise/trace_spec.rb
opal-0.7.0 spec/opal/stdlib/promise/trace_spec.rb
opal-0.7.0.rc1 spec/opal/stdlib/promise/trace_spec.rb
opal-0.7.0.beta3 spec/opal/stdlib/promise/trace_spec.rb
opal-0.7.0.beta2 spec/opal/stdlib/promise/trace_spec.rb