Sha256: 6fe7fdb11714e88cc2394e7086f43cf1080d0a0a244ba34ee584652e5539cf81

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
$:.unshift File.dirname(__FILE__)

require 'time'
require 'shared'
module Promising
  describe Future do

    before :each do
      @method = Kernel.method(:future)
    end

    if defined?(BasicObject)
      it "should inherit from BasicObject if available, and not otherwise" do
        expect(Future.ancestors).to include BasicObject
      end
    end

    it_should_behave_like "A Promise"

    it "should work in the background" do
      start = Time.now
      x = future { sleep 3; 5 }
      middle = Time.now
      y = x + 5
      expect(y).to eq 10
      finish = Time.now
      expect(middle - start).to be_within(10**-2).of(0)
      expect(finish - start).to be_within(10**-2).of(3)
    end

    it "should finished when timeout" do
      # timeout
      x = future(timeout:1){ sleep 2; 5 }
      expect{x + 5}.to raise_error(::Timeout::Error)

      # not timeout
      x = future(timeout:2){ sleep 1; 5 }
      expect(x + 5).to eq 10
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
promising-0.3.1 spec/future_spec.rb