Sha256: bb5d54e117ed8834e0dfa26a49271c71abd317f55e4f54da185892dd2273b1f2
Contents?: true
Size: 1.68 KB
Versions: 3
Compression:
Stored size: 1.68 KB
Contents
describe Onfido::Resource do subject(:resource) { described_class.new } let(:endpoint) { 'https://api.onfido.com/v1/' } let(:path) { 'addresses/pick' } let(:api_key) { 'some_key' } before do allow(Onfido).to receive(:endpoint).and_return(endpoint) allow(Onfido).to receive(:api_key).and_return(api_key) end describe '#url_for' do it 'composes the full api url' do expect(resource.url_for(path)).to eq(endpoint + path) end end describe '#method_missing' do %i(put delete patch).each do |method| context "for unsupported HTTP method: #{method}" do it 'raises an error' do expect { resource.public_send(method) }.to raise_error(NoMethodError) end end end %i(get post).each do |method| context "for supported HTTP method: #{method}" do let(:url) { endpoint + path } let(:payload) { {postcode: 'SE1 4NG'} } let(:response) do { 'addresses' => [ { 'street' => 'Main Street', 'town' => 'London', 'postcode' => 'SW4 6EH', 'country' => 'GBR' } ] } end before do expect(RestClient::Request).to receive(:execute) .with( url: url, payload: Rack::Utils.build_query(payload), method: method, headers: resource.headers ) .and_return(response) end it 'makes a request to an endpoint' do expect(resource.public_send(method, {url: url, payload: payload})).to eq(response) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
onfido-0.0.3 | spec/onfido/resource_spec.rb |
onfido-0.0.2 | spec/onfido/resource_spec.rb |
onfido-0.0.1 | spec/onfido/resource_spec.rb |