Sha256: 33a635f20aa943b2abba25e70c7efa50b64acf6557033a91e8bfeaa38ec706b5

Contents?: true

Size: 1.4 KB

Versions: 10

Compression:

Stored size: 1.4 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- 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 "#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

10 entries across 10 versions & 2 rubygems

Version Path
ethon-0.10.1 spec/ethon/easy/callbacks_spec.rb
ethon-0.10.0 spec/ethon/easy/callbacks_spec.rb
ethon-0.9.1 spec/ethon/easy/callbacks_spec.rb
ethon-0.9.0 spec/ethon/easy/callbacks_spec.rb
ethon-0.8.1 spec/ethon/easy/callbacks_spec.rb
dwolla_swagger-1.0.6 vendor/bundle/ruby/2.2.0/gems/ethon-0.8.0/spec/ethon/easy/callbacks_spec.rb
ethon-0.8.0 spec/ethon/easy/callbacks_spec.rb
ethon-0.7.4 spec/ethon/easy/callbacks_spec.rb
ethon-0.7.3 spec/ethon/easy/callbacks_spec.rb
ethon-0.7.2 spec/ethon/easy/callbacks_spec.rb