Sha256: 4a6e4be3369e2e51627dcf7b98de0129f0c94d0ea6f06e5cab198a3a65b0b84c

Contents?: true

Size: 1.54 KB

Versions: 34

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper'

describe Ethon::Easy::Callbacks do
  let!(:easy) { Ethon::Easy.new }

  describe "#set_callbacks" do
    before do
      expect(Ethon::Curl).to receive(:set_option).exactly(3).times
    end

    it "sets write-, debug-, and headerfunction" do
      easy.set_callbacks
    end

    it "resets @response_body" do
      easy.set_callbacks
      expect(easy.instance_variable_get(:@response_body)).to eq("")
    end

    it "resets @response_headers" do
      easy.set_callbacks
      expect(easy.instance_variable_get(:@response_headers)).to eq("")
    end

    it "resets @debug_info" do
      easy.set_callbacks
      expect(easy.instance_variable_get(:@debug_info).to_a).to eq([])
    end
  end

  describe "#progress_callback" do
    it "returns 0" do
      expect(easy.progress_callback.call(0,1,1,1,1)).to be(0)
    end
  end

  describe "#body_write_callback" do
    let(:body_write_callback) { easy.instance_variable_get(:@body_write_callback) }
    let(:stream) { double(:read_string => "") }
    context "when body returns not :abort" do
      it "returns number bigger than 0" do
        expect(body_write_callback.call(stream, 1, 1, nil) > 0).to be(true)
      end
    end

    context "when body returns :abort" do
      before do
        easy.on_body.clear
        easy.on_body { :abort }
      end
      let(:body_write_callback) { easy.instance_variable_get(:@body_write_callback) }

      it "returns -1 to indicate abort to libcurl" do
        expect(body_write_callback.call(stream, 1, 1, nil)).to eq(-1)
      end
    end
  end
end

Version data entries

34 entries across 33 versions & 7 rubygems

Version Path
cloudsmith-api-0.49.94 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/spec/ethon/easy/callbacks_spec.rb
cloudsmith-api-0.49.21 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/spec/ethon/easy/callbacks_spec.rb
cloudsmith-api-0.49.15 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/spec/ethon/easy/callbacks_spec.rb
cloudsmith-api-0.49.13 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/spec/ethon/easy/callbacks_spec.rb
cloudsmith-api-0.49.9 vendor/bundle/ruby/2.3.0/gems/ethon-0.12.0/spec/ethon/easy/callbacks_spec.rb
cloudsmith-api-0.44.4 vendor/bundle/ruby/2.3.0/gems/ethon-0.12.0/spec/ethon/easy/callbacks_spec.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/ethon-0.11.0/spec/ethon/easy/callbacks_spec.rb
approveapi-1.0.8 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/spec/ethon/easy/callbacks_spec.rb
approveapi-1.0.5 vendor/bundle/ruby/2.6.0/gems/ethon-0.12.0/spec/ethon/easy/callbacks_spec.rb
ethon-0.12.0 spec/ethon/easy/callbacks_spec.rb
cloudsmith-api-0.30.7 vendor/bundle/ruby/2.3.0/gems/ethon-0.11.0/spec/ethon/easy/callbacks_spec.rb
color_me_shop-1.0.0 vendor/bundle/ruby/2.5.0/gems/ethon-0.11.0/spec/ethon/easy/callbacks_spec.rb
cloudsmith-api-0.21.4 vendor/bundle/ruby/2.3.0/gems/ethon-0.11.0/spec/ethon/easy/callbacks_spec.rb
ethon-0.11.0 spec/ethon/easy/callbacks_spec.rb