Sha256: 7f91ba99a8b1d97358f549d051a7ff7de354011e6fbf38a15a892bd608437677

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

require_relative '../test_helper'

module Excon
  # EdgeCaseTest
  #
  # Validate edge cases (or: non-happy path)
  #
  class EdgeCaseTest < HyperMediaTest
    def empty_json_resource
      empty_json_response.resource
    end

    def test_missing_middleware
      Excon.defaults[:middlewares].delete(Excon::HyperMedia::Middleware)

      assert_raises(NoMethodError) { api.rel }
    end

    def test_rel_missing_name
      ex = assert_raises(ArgumentError) { api.rel }
      assert_equal 'missing relation name', ex.message
    end

    def test_rel_missing_arguments
      assert_equal Excon::Connection, api.rel('self').class
    end

    def test_rel_unknown_relation
      ex = assert_raises(Excon::HyperMedia::UnknownRelationError) { api.rel('invalid') }
      assert_equal 'unknown relation: invalid', ex.message
    end

    def test_missing_links
      assert_equal({}, empty_json_resource._links.to_h)
    end

    def test_missing_embedded
      assert_equal({}, empty_json_resource._embedded.to_h)
    end

    def test_missing_properties
      assert_equal({}, empty_json_resource._properties.to_h)
    end

    def test_unknown_property
      assert_equal nil, api.resource._properties.invalid
      assert_equal nil, api.resource._properties['invalid']
    end

    def test_unknown_link
      assert_equal nil, empty_json_resource._links.invalid
      assert_equal nil, empty_json_resource._links['invalid']
    end

    def test_unknown_embed
      assert_equal nil, api.resource._embedded.invalid
      assert_equal nil, api.resource._embedded['invalid']
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
excon-hypermedia-0.5.3 test/excon/edgecase_test.rb