Sha256: 61d081f7cff683352b4717d7ae70d654a1b909b37e42a2dbbb97237ecb255973
Contents?: true
Size: 1.46 KB
Versions: 8
Compression:
Stored size: 1.46 KB
Contents
require "spec_helper" describe Alephant::Publisher::Request::Connection do let (:driver) { instance_double(Faraday::Connection, :get => nil) } let (:uri) { "/foo/bar/baz" } subject { described_class.new driver } describe "#get" do let (:expected_raw_data) do { :some => 'data' } end let (:expected_data) { JSON.generate(expected_raw_data, :symbolize_names => true) } let (:expected_response) { instance_double(Faraday::Response, :body => expected_data, :status => 200) } context "with a valid endpoint" do before(:each) do allow(driver).to receive(:get).and_return(expected_response) end specify { expect(subject.get(uri)).to eq expected_raw_data } end context "invalid hostname" do let (:expected_exception) { Alephant::Publisher::Request::ConnectionFailed } let (:faraday_exception) { Faraday::ConnectionFailed.new(StandardError) } before(:each) do allow(driver).to receive(:get).and_raise(faraday_exception) end specify { expect { subject.get(uri)}.to raise_error expected_exception } end context "invalid status code" do let (:status_code) { 503 } let (:expected_exception) { Alephant::Publisher::Request::InvalidApiStatus } before(:each) do allow(driver).to receive(:get).and_return(OpenStruct.new(:status => status_code)) end specify { expect { subject.get(uri)}.to raise_error expected_exception } end end end
Version data entries
8 entries across 8 versions & 1 rubygems