Sha256: 2e8dcf9cb462a89746652f8b97c624030ea6787fcb5a0cfe06ef73bcd60ab428

Contents?: true

Size: 1.04 KB

Versions: 143

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Faraday
  module StreamingResponseChecker
    def check_streaming_response(streamed, options = {})
      opts = {
        prefix: '',
        streaming?: true
      }.merge(options)

      expected_response = opts[:prefix] + big_string

      chunks, sizes = streamed.transpose

      # Check that the total size of the chunks (via the last size returned)
      # is the same size as the expected_response
      expect(sizes.last).to eq(expected_response.bytesize)

      start_index = 0
      expected_chunks = []
      chunks.each do |actual_chunk|
        expected_chunk = expected_response[start_index..((start_index + actual_chunk.bytesize) - 1)]
        expected_chunks << expected_chunk
        start_index += expected_chunk.bytesize
      end

      # it's easier to read a smaller portion, so we check that first
      expect(expected_chunks[0][0..255]).to eq(chunks[0][0..255])

      [expected_chunks, chunks].transpose.each do |expected, actual|
        expect(actual).to eq(expected)
      end
    end
  end
end

Version data entries

143 entries across 130 versions & 20 rubygems

Version Path
es_cli-0.1.0 vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/streaming_response_checker.rb
avalara_sdk-24.12.2 vendor/bundle/ruby/2.7.0/gems/faraday-1.10.4/spec/support/streaming_response_checker.rb
avalara_sdk-24.12.1 vendor/bundle/ruby/2.7.0/gems/faraday-1.10.4/spec/support/streaming_response_checker.rb
avalara_sdk-24.12.0 vendor/bundle/ruby/2.7.0/gems/faraday-1.10.4/spec/support/streaming_response_checker.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/faraday-1.10.3/spec/support/streaming_response_checker.rb
faraday-2.12.2 spec/support/streaming_response_checker.rb
faraday-2.12.1 spec/support/streaming_response_checker.rb
moneykit-0.1.15 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/streaming_response_checker.rb
moneykit-0.1.14 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/streaming_response_checker.rb
faraday-1.10.4 spec/support/streaming_response_checker.rb
faraday-2.12.0 spec/support/streaming_response_checker.rb
faraday-2.11.0 spec/support/streaming_response_checker.rb
moneykit-0.1.13 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/streaming_response_checker.rb
moneykit-0.1.12 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/streaming_response_checker.rb
moneykit-0.1.11 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/streaming_response_checker.rb
faraday-2.10.1 spec/support/streaming_response_checker.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/faraday-1.2.0/spec/support/streaming_response_checker.rb
faraday-2.10.0 spec/support/streaming_response_checker.rb
faraday-2.9.2 spec/support/streaming_response_checker.rb
faraday-2.9.1 spec/support/streaming_response_checker.rb