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
|
# frozen_string_literal: true
RSpec.describe FaradayMiddleware::Rashify do
context 'when used', type: :response do
it 'creates a Hashie::Rash from the body' do
body = { 'name' => 'Erik Michaels-Ober', 'username' => 'sferik' }
me = process(body).body
expect(me.name).to eq('Erik Michaels-Ober')
expect(me.username).to eq('sferik')
end
it 'handles strings' do
body = 'Most amazing string EVER'
me = process(body).body
expect(me).to eq('Most amazing string EVER')
end
it 'handles hashes and decamelcase the keys' do
body = { 'name' => 'Erik Michaels-Ober', 'userName' => 'sferik' }
me = process(body).body
expect(me.name).to eq('Erik Michaels-Ober')
expect(me.user_name).to eq('sferik')
end
it 'handles arrays' do
body = [123, 456]
values = process(body).body
expect(values).to eq([123, 456])
end
it 'handles arrays of hashes' do
body = [{ 'username' => 'sferik' }, { 'username' => 'pengwynn' }]
us = process(body).body
expect(us.first.username).to eq('sferik')
expect(us.last.username).to eq('pengwynn')
end
it 'handles mixed arrays' do
body = [123, { 'username' => 'sferik' }, 456]
values = process(body).body
expect(values.first).to eq(123)
expect(values.last).to eq(456)
expect(values[1].username).to eq('sferik')
end
end
end
|