From bba3a082431f26fa976dec0adbfb75ef7d13e14f Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 11 Feb 2019 10:38:41 +1100 Subject: [PATCH] feat: update http client code --- lib/pact/hal/http_client.rb | 4 ++++ lib/pact/hal/link.rb | 12 ++++++++++++ spec/lib/pact/hal/http_client_spec.rb | 3 +-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/pact/hal/http_client.rb b/lib/pact/hal/http_client.rb index 21428439..4395c0bb 100644 --- a/lib/pact/hal/http_client.rb +++ b/lib/pact/hal/http_client.rb @@ -68,6 +68,10 @@ def raw_body __getobj__().body end + def status + code.to_i + end + def success? __getobj__().code.start_with?("2") end diff --git a/lib/pact/hal/link.rb b/lib/pact/hal/link.rb index 24e8cafb..6b5b20f4 100644 --- a/lib/pact/hal/link.rb +++ b/lib/pact/hal/link.rb @@ -24,6 +24,18 @@ def run(payload = nil) end end + def title_or_name + title || name + end + + def title + @attrs['title'] + end + + def name + @attrs['name'] + end + def get(payload = {}, headers = {}) wrap_response(href, @http_client.get(href, payload, headers)) end diff --git a/spec/lib/pact/hal/http_client_spec.rb b/spec/lib/pact/hal/http_client_spec.rb index de45d6d3..209cec18 100644 --- a/spec/lib/pact/hal/http_client_spec.rb +++ b/spec/lib/pact/hal/http_client_spec.rb @@ -3,12 +3,11 @@ module Pact module Hal describe HttpClient do - before do allow(Retry).to receive(:until_true) { |&block| block.call } end - subject { HttpClient.new(username: 'foo', password: 'bar' ) } + subject { HttpClient.new(username: 'foo', password: 'bar') } describe "get" do let!(:request) do