forked from Dinda-com-br/braspag-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse_spec.rb
42 lines (34 loc) · 1.3 KB
/
response_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
require 'spec_helper'
describe BraspagRest::Response do
describe '#success' do
context 'when gateway status code is 200..207' do
it 'returns true' do
(200..207).each do |code|
gateway_response = Hashie::Mash.new(code: code, body: '{}')
expect(BraspagRest::Response.new(gateway_response)).to be_success
end
end
end
context 'when gateway status code is not 200..207' do
let(:gateway_response) { Hashie::Mash.new(code: 400, body: '{}') }
it 'returns false' do
expect(BraspagRest::Response.new(gateway_response)).not_to be_success
gateway_response.code = 500
expect(BraspagRest::Response.new(gateway_response)).not_to be_success
end
end
context 'when gateway returns an error' do
let(:gateway_response) { Hashie::Mash.new(body: 'an error happened') }
it 'returns false' do
expect(BraspagRest::Response.new(gateway_response)).not_to be_success
end
end
end
describe '#parsed_body' do
let(:gateway_response) { Hashie::Mash.new(code: 200, body: '{"Name" : "Maria"}') }
subject(:response) { BraspagRest::Response.new(gateway_response) }
it 'returns the body gateway response as a hash' do
expect(response.parsed_body).to eq({ 'Name' => 'Maria' })
end
end
end