Sha256: 6699d5f6dbe5e689ba4ad13c9268c3cf1b53e9e44d75096ddb44792ec57a004e
Contents?: true
Size: 1.08 KB
Versions: 8
Compression:
Stored size: 1.08 KB
Contents
require 'spec_helper' describe 'ProjectAPI' do describe '#request' do let(:endpoint) { "https://my-awesome-api.com" } let(:verb) { :post } let(:path) { '/greeting' } let(:options) do { body: { foo: 'bar' }, headers: { 'X-Access-Token' => 'secret-token' } } end let(:api) do api = CmQuiz::ProjectAPI.new(endpoint) end it "should request clearbit" do stub_request(verb, "#{endpoint}#{path}") api.request(verb, path, options) assert_requested(verb, "#{endpoint}#{path}") do |req| body = JSON.parse(req.body) expect(body['foo']).to eq('bar') expect(req.headers['X-Access-Token']).to eq(options[:headers]['X-Access-Token']) end end context "when response is not success" do it "should raise exception" do res_body = 'error_message' stub_request(verb, "#{endpoint}#{path}").to_return(status: 404, body: res_body) expect { api.request(verb, path, options) }.to raise_error(CmQuiz::ProjectAPI::PerformFailed) end end end end
Version data entries
8 entries across 8 versions & 1 rubygems