Sha256: 7579a336b04cd82c15fb0630efc0729a7c67018a26f431ad6b16a25b5b700a0d

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

require "spec_helper"
require "faraday"

describe Faraday::Response::RaiseBalancedError, :type => :response do
  context "when used" do
    let(:raise_server_error) { described_class.new }
  end

  context "integration test" do

    before(:each) do
      Faraday::Response.register_middleware :handle_balanced_errors => lambda { described_class }
      VCR.turn_off!
    end

    after(:each)  do
      VCR.turn_on!
    end

    let(:stubs) { Faraday::Adapter::Test::Stubs.new }
    let(:connection) do
      Faraday::Connection.new do |builder|
        builder.response :handle_balanced_errors
        builder.response :json
        builder.adapter :test, stubs
      end
    end

    it "should raise exceptions on bad request errors" do
      stubs.get("/error") {
        [400, {}, JSON.dump({
            :status =>"Bad Request",
            :status_code =>400,
            :description => "Missing expected field expiration_year Your request "\
                            "id is OHM62bf258abfea11e1aaba026ba7e5e72e.",
            :request_id => "OHM62bf258abfea11e1aaba026ba7e5e72e"
        })]
      }

      lambda {
        connection.get('/error')
      }.should raise_error(Balanced::BadRequest)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
balanced-1.2.1 spec/balanced/response/balanced_exception_middleware_spec.rb
balanced-1.1.1 spec/balanced/response/balanced_exception_middleware_spec.rb
balanced-1.1.0 spec/balanced/response/balanced_exception_middleware_spec.rb