spec/routemaster/responses/hateoas_response_spec.rb in routemaster-drain-2.3.0 vs spec/routemaster/responses/hateoas_response_spec.rb in routemaster-drain-2.4.0

- old
+ new

@@ -1,60 +1,59 @@ require 'spec_helper' require 'routemaster/responses/hateoas_response' -module Routemaster - module Responses - RSpec.describe HateoasResponse do - let(:response) { double('Response', status: status, body: body, headers: headers) } - let(:status) { 200 } - let(:body) { {}.to_json } - let(:headers) { {} } +# need to laod this here to resolve circular dependency +require 'routemaster/resources/rest_resource' - subject { described_class.new(response) } +describe Routemaster::Responses::HateoasResponse do + let(:response) { double('Response', status: status, body: body, headers: headers) } + let(:status) { 200 } + let(:body) { {}.to_json } + let(:headers) { {} } - context 'link traversal' do - let(:body) do - { - '_links' => { - 'self' => { 'href' => 'self_url' }, - 'resource_a' => { 'href' => 'resource_a_url' }, - 'resource_b' => { 'href' => 'resource_b_url' } - } - } - end + subject { described_class.new(response) } - it 'creates a method for every key in _links attribute' do - expect(subject.resource_a.url).to eq('resource_a_url') - expect(subject.resource_b.url).to eq('resource_b_url') - end + context 'link traversal' do + let(:body) do + { + '_links' => { + 'self' => { 'href' => 'self_url' }, + 'resource_a' => { 'href' => 'resource_a_url' }, + 'resource_b' => { 'href' => 'resource_b_url' } + } + } + end - it 'creates a _self method if there is a link with name self' do - expect(subject._self.url).to eq('self_url') - end + it 'creates a method for every key in _links attribute' do + expect(subject.resource_a.url).to eq('resource_a_url') + expect(subject.resource_b.url).to eq('resource_b_url') + end - it 'raise an exception when requested link does not exist' do - expect { subject.some_unsupported_link }.to raise_error(NoMethodError) - end + it 'creates a _self method if there is a link with name self' do + expect(subject._self.url).to eq('self_url') + end - describe '#body_without_links' do - before do - body.merge!('foo' => 'bar') - end + it 'raise an exception when requested link does not exist' do + expect { subject.some_unsupported_link }.to raise_error(NoMethodError) + end - it 'returns the body without the _links key' do - expect(subject.body_without_links).to eq({ 'foo' => 'bar' }) - end - end + describe '#body_without_links' do + before do + body.merge!('foo' => 'bar') + end - describe '#has?' do - it 'returns true for an existing link' do - expect(subject.has?(:resource_a)).to be_truthy - end + it 'returns the body without the _links key' do + expect(subject.body_without_links).to eq({ 'foo' => 'bar' }) + end + end - it 'returns false for a non existing link' do - expect(subject.has?(:other_resource)).to be_falsy - end - end + describe '#has?' do + it 'returns true for an existing link' do + expect(subject.has?(:resource_a)).to be_truthy + end + + it 'returns false for a non existing link' do + expect(subject.has?(:other_resource)).to be_falsy end end end end