Sha256: 5d479bae0f3a182e0b176c5b910fca1351bfb5b95e4598760ea13cd7e2635ae9

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

module Bacon
  class Context
    include ::Elevate
  end
end

describe Elevate do
  describe "#async" do
    it "runs the specified task asynchronously" do
      async do
        task do
          true
        end

        on_finish do |result, exception|
          @called = result
          resume
        end
      end

      wait_max 1.0 do
        @called.should.be.true
      end
    end

    it "passes provided args to the task as instance variables" do
      async name: "harry" do
        task do
          @name
        end

        on_finish do |name, exception|
          @result = name
          resume
        end
      end

      wait_max 1.0 do
        @result.should == "harry"
      end
    end

    it "allows tasks to report progress" do
      @updates = []

      async do
        task do
          sleep 0.1
          yield 1
          sleep 0.2
          yield 2
          sleep 0.3
          yield 3

          true
        end

        on_update do |count|
          @updates << count
        end

        on_finish do |result, exception|
          resume
        end
      end

      wait_max 1.0 do
        @updates.should == [1,2,3]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
elevate-0.5.0 spec/api_spec.rb