Sha256: 8452113c2c9b2d0cec052d5f8fa340f7b3429eca69f0721908b057f6848d0f55
Contents?: true
Size: 1.01 KB
Versions: 49
Compression:
Stored size: 1.01 KB
Contents
require 'promise' describe 'Promise#always' do it 'calls the block when it was resolved' do x = 42 Promise.value(23).then { |v| x = v }.always { |v| x = 2 } x.should == 2 end it 'calls the block when it was rejected' do x = 42 Promise.error(23).rescue { |v| x = v }.always { |v| x = 2 } x.should == 2 end it 'acts as resolved' do x = 42 Promise.error(23).rescue { |v| x = v }.always { x = 2 }.then { x = 3 } x.should == 3 end it 'can be called multiple times on resolved promises' do p = Promise.value(2) x = 1 p.then { x += 1 } p.fail { x += 2 } p.always { x += 3 } x.should == 5 end it 'can be called multiple times on rejected promises' do p = Promise.error(2) x = 1 p.then { x += 1 } p.fail { x += 2 } p.always { x += 3 } x.should == 6 end it 'raises with always! if a promise has already been chained' do p = Promise.new p.then! {} proc { p.always! {} }.should raise_error(ArgumentError) end end
Version data entries
49 entries across 49 versions & 1 rubygems