Sha256: c230a07cdb25990874fc0cdda11110bb636ca37036c9c3e6ce396e55cf33e483

Contents?: true

Size: 1.84 KB

Versions: 47

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

RSpec.describe Faraday::Env do
  subject(:env) { described_class.new }

  it 'allows to access members' do
    expect(env.method).to be_nil
    env.method = :get
    expect(env.method).to eq(:get)
  end

  it 'allows to access symbol non members' do
    expect(env[:custom]).to be_nil
    env[:custom] = :boom
    expect(env[:custom]).to eq(:boom)
  end

  it 'allows to access string non members' do
    expect(env['custom']).to be_nil
    env['custom'] = :boom
    expect(env['custom']).to eq(:boom)
  end

  it 'ignores false when fetching' do
    ssl = Faraday::SSLOptions.new
    ssl.verify = false
    expect(ssl.fetch(:verify, true)).to be_falsey
  end

  it 'handle verify_hostname when fetching' do
    ssl = Faraday::SSLOptions.new
    ssl.verify_hostname = true
    expect(ssl.fetch(:verify_hostname, false)).to be_truthy
  end

  it 'retains custom members' do
    env[:foo] = 'custom 1'
    env[:bar] = :custom2
    env2 = Faraday::Env.from(env)
    env2[:baz] = 'custom 3'

    expect(env2[:foo]).to eq('custom 1')
    expect(env2[:bar]).to eq(:custom2)
    expect(env[:baz]).to be_nil
  end

  describe '#body' do
    subject(:env) { described_class.from(body: { foo: 'bar' }) }

    context 'when response is not finished yet' do
      it 'returns the request body' do
        expect(env.body).to eq(foo: 'bar')
      end
    end

    context 'when response is finished' do
      before do
        env.status = 200
        env.body = { bar: 'foo' }
        env.response = Faraday::Response.new(env)
      end

      it 'returns the response body' do
        expect(env.body).to eq(bar: 'foo')
      end

      it 'allows to access request_body' do
        expect(env.request_body).to eq(foo: 'bar')
      end

      it 'allows to access response_body' do
        expect(env.response_body).to eq(bar: 'foo')
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 4 rubygems

Version Path
faraday-2.12.1 spec/faraday/options/env_spec.rb
moneykit-0.1.15 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/options/env_spec.rb
moneykit-0.1.14 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/options/env_spec.rb
faraday-2.12.0 spec/faraday/options/env_spec.rb
faraday-2.11.0 spec/faraday/options/env_spec.rb
moneykit-0.1.13 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/options/env_spec.rb
moneykit-0.1.12 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/options/env_spec.rb
moneykit-0.1.11 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/options/env_spec.rb
faraday-2.10.1 spec/faraday/options/env_spec.rb
faraday-2.10.0 spec/faraday/options/env_spec.rb
faraday-2.9.2 spec/faraday/options/env_spec.rb
faraday-2.9.1 spec/faraday/options/env_spec.rb
moneykit-0.1.10 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/options/env_spec.rb
moneykit-0.1.9 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/options/env_spec.rb
moneykit-0.1.6 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/options/env_spec.rb
moneykit-0.1.5 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/options/env_spec.rb
moneykit-0.1.4 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/options/env_spec.rb
moneykit-0.1.3 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/options/env_spec.rb
faraday-2.9.0 spec/faraday/options/env_spec.rb
faraday-2.8.1 spec/faraday/options/env_spec.rb