Sha256: 38dda6b2fd77f5a23b5a5d48950f9be6cb934eb816ca032a1f7cbec740af88fc

Contents?: true

Size: 1.25 KB

Versions: 63

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper'

describe Acfs::Request::Callbacks do
  let(:callback) { lambda { |res| } }
  let(:request)  { Acfs::Request.new('fubar') }

  describe '#on_complete' do
    it 'should store a given callback' do
      request.on_complete &callback

      expect(request.callbacks).to have(1).item
      expect(request.callbacks[0]).to be == callback
    end

    it 'should store multiple callback' do
      request.on_complete { |res| "abc" }
      request.on_complete &callback

      expect(request.callbacks).to have(2).item
      expect(request.callbacks[0]).to be == callback
    end
  end

  describe '#complete!' do
    let(:response) { Acfs::Response.new(request) }

    it 'should trigger registered callbacks with given response' do
      expect(callback).to receive(:call).with(response, kind_of(Proc))

      request.on_complete &callback
      request.complete! response
    end

    it 'should trigger multiple callback in reverted insertion order' do
      check = []

      request.on_complete { |res, nxt| check << 1; nxt.call res }
      request.on_complete { |res, nxt| check << 2; nxt.call res }
      request.on_complete { |res, nxt| check << 3; nxt.call res }

      request.complete! response

      expect(check).to be == [3, 2, 1]
    end
  end
end

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
acfs-0.42.0 spec/acfs/request/callbacks_spec.rb
acfs-0.41.1 spec/acfs/request/callbacks_spec.rb
acfs-0.41.1.beta1 spec/acfs/request/callbacks_spec.rb
acfs-0.41.0 spec/acfs/request/callbacks_spec.rb
acfs-0.40.1.rc1 spec/acfs/request/callbacks_spec.rb
acfs-0.40.0 spec/acfs/request/callbacks_spec.rb
acfs-0.39.1 spec/acfs/request/callbacks_spec.rb
acfs-0.39.0 spec/acfs/request/callbacks_spec.rb
acfs-1.0.0.dev.1.b305 spec/acfs/request/callbacks_spec.rb
acfs-0.38.0 spec/acfs/request/callbacks_spec.rb
acfs-1.0.0.dev.1.b298 spec/acfs/request/callbacks_spec.rb
acfs-1.0.0.dev.1.b297 spec/acfs/request/callbacks_spec.rb
acfs-0.37.0.1.b295 spec/acfs/request/callbacks_spec.rb
acfs-0.37.0 spec/acfs/request/callbacks_spec.rb
acfs-0.36.0.1.b293 spec/acfs/request/callbacks_spec.rb
acfs-0.36.0 spec/acfs/request/callbacks_spec.rb
acfs-0.35.0.1.b291 spec/acfs/request/callbacks_spec.rb
acfs-0.35.0 spec/acfs/request/callbacks_spec.rb
acfs-0.34.1.1.b289 spec/acfs/request/callbacks_spec.rb
acfs-0.34.1 spec/acfs/request/callbacks_spec.rb