Sha256: 8c33d926cb6f59dbb15f7982e5ed63007e530cf269508d51f5e5658b9edffef3

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true
# rubocop:disable Metrics/MethodLength

require_relative '../test_helper'

module Excon
  # ResourceObjectTest
  #
  # Validate the workings of `Excon::HyperResource::ResourceObject`.
  #
  class ResourceObjectTest < Minitest::Test
    def body
      <<-EOF
        {
          "_links": {
            "hello": {
              "href": "http://www.example.com/hello/{location}"
            }
          },
          "uid": "universe",
          "hello": "world"
        }
      EOF
    end

    def data
      @data ||= JSON.parse(body)
    end

    def resource
      @resource ||= Excon::HyperMedia::ResourceObject.new(data)
    end

    def test_resource
      assert_equal data, resource.instance_variable_get(:@data)
    end

    def test_links
      assert_equal data['_links']['hello']['href'], resource._links.hello.href
    end

    def test_properties
      assert_equal 'universe', resource.uid
      assert_equal 'world', resource.hello
      assert_equal 'world', resource['hello']
      assert_equal nil, resource['invalid']
    end

    def test_correctly_raising_no_method_error
      assert_raises(NoMethodError) { resource.invalid }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
excon-hypermedia-0.5.2 test/excon/resource_object_test.rb