Sha256: c4aff04afd9385d3729e994b4f44f905730087b1b5808e47f1e0511ef3bfaaff

Contents?: true

Size: 1.45 KB

Versions: 47

Compression:

Stored size: 1.45 KB

Contents

require "spec_helper"

describe Brightbox::ErrorParser do

  describe "#pretty_print" do
    let(:parser) { Brightbox::ErrorParser.new(error_to_parse) }

    context "when passed an Unauthorized error" do
      let(:msg) { double }
      let(:request) { double }
      let(:response) { double :body => json_response }

      let(:json_response) do
        <<-EOS
        {
          "error": "invalid_token",
          "error_description": "The OAuth token can not be found"
        }
        EOS
      end

      let(:error_to_parse) { Excon::Errors::Unauthorized.new(msg, request, response) }

      it "returns the response from the JSON" do
        expect(parser).to receive(:error).with("ERROR: invalid_token")
        parser.pretty_print
      end
    end

    context "when passed a ServiceUnavailable error" do
      let(:msg) { double }
      let(:request) { double }
      let(:response) { double }
      let(:error_to_parse) { Excon::Errors::ServiceUnavailable.new(msg, request, response) }

      it "returns a warning the API is missing" do
        expect(parser).to receive(:error).with("Api currently unavailable")
        parser.pretty_print
      end
    end

    context "when passed a non Excon error" do
      let(:msg) { "fnord is a required MuGuffin" }
      let(:error_to_parse) { ArgumentError.new(msg) }

      it "returns the error name" do
        expect(parser).to receive(:error).with("ERROR: #{msg}")
        parser.pretty_print
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
brightbox-cli-3.3.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-3.2.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-3.1.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-3.0.1 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-3.0.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-2.12.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-2.11.2 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-2.11.1 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-2.11.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-2.10.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-2.9.3 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-2.9.2 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-2.9.1 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-2.9.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-2.8.2 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-2.8.1 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-2.8.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-2.7.1 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-2.7.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-2.6.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb