-
Notifications
You must be signed in to change notification settings - Fork 968
/
env_spec.rb
70 lines (57 loc) · 1.68 KB
/
env_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 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