Sha256: 2fe13b5eecb9f494192d4539d8cc508f7644826de2888d8d7f3e5bb18bf1fd19

Contents?: true

Size: 1.67 KB

Versions: 79

Compression:

Stored size: 1.67 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 'retains custom members' do
    env[:foo] = 'custom 1'
    env[:bar] = :custom_2
    env2 = Faraday::Env.from(env)
    env2[:baz] = 'custom 3'

    expect(env2[:foo]).to eq('custom 1')
    expect(env2[:bar]).to eq(:custom_2)
    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

79 entries across 66 versions & 15 rubygems

Version Path
faraday-1.10.4 spec/faraday/options/env_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/faraday-1.2.0/spec/faraday/options/env_spec.rb
avalara_sdk-24.2.29 vendor/bundle/ruby/2.7.0/gems/faraday-1.10.3/spec/faraday/options/env_spec.rb
faraday-1.10.3 spec/faraday/options/env_spec.rb
faraday-1.10.2 spec/faraday/options/env_spec.rb
faraday-1.10.1 spec/faraday/options/env_spec.rb
alloy_sdk-0.1.0 vendor/bundle/ruby/3.0.0/gems/faraday-1.0.1/spec/faraday/options/env_spec.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/faraday-1.10.0/spec/faraday/options/env_spec.rb
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/faraday-1.10.0/spec/faraday/options/env_spec.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/faraday-1.10.0/spec/faraday/options/env_spec.rb
faraday-1.10.0 spec/faraday/options/env_spec.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/faraday-1.9.3/spec/faraday/options/env_spec.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/faraday-1.8.0/spec/faraday/options/env_spec.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/faraday-1.9.3/spec/faraday/options/env_spec.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/faraday-1.9.3/spec/faraday/options/env_spec.rb
faraday-1.9.3 spec/faraday/options/env_spec.rb
faraday-1.9.2 spec/faraday/options/env_spec.rb
faraday-1.9.1 spec/faraday/options/env_spec.rb
faraday-1.9.0 spec/faraday/options/env_spec.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/faraday-1.8.0/spec/faraday/options/env_spec.rb