Sha256: a777be30b3b067f2b006f7485fbcd2e5455531c362db998dbab68321a235907b

Contents?: true

Size: 1.45 KB

Versions: 18

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

18 entries across 18 versions & 1 rubygems

Version Path
brightbox-cli-5.0.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-5.0.0.rc2 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-5.0.0.rc1 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-5.0.0.alpha spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-4.8.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-4.7.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-4.6.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-4.5.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-4.5.0.rc1 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-4.4.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-4.3.2 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-4.3.1 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-4.3.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-4.2.1 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-4.2.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-4.1.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-4.0.0 spec/unit/brightbox/error_parser/pretty_print_spec.rb
brightbox-cli-4.0.0.rc2 spec/unit/brightbox/error_parser/pretty_print_spec.rb