-
Notifications
You must be signed in to change notification settings - Fork 3
/
animal_service_client_spec.rb
74 lines (59 loc) · 2.26 KB
/
animal_service_client_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require_relative 'pact_helper'
require 'zoo_app/animal_service_client'
module ZooApp
describe AnimalServiceClient do
include Pact::Consumer::Minitest
before do
AnimalServiceClient.base_uri animal_service.mock_service_base_url
end
describe ".find_alligator_by_name" do
describe "when an alligator by the given name exists" do
before do
animal_service.given("there is an alligator named Mary").
upon_receiving("a request for an alligator").with(
method: :get,
path: '/alligators/Mary',
headers: {'Accept' => 'application/json'} ).
will_respond_with(
status: 200,
headers: {'Content-Type' => 'application/json;charset=utf-8'},
body: {name: 'Mary'}
)
end
it "returns the alligator" do
assert_equal(AnimalServiceClient.find_alligator_by_name("Mary"), ZooApp::Animals::Alligator.new(name: 'Mary'))
end
end
describe "when an alligator by the given name does not exist" do
before do
animal_service.given("there is not an alligator named Mary").
upon_receiving("a request for an alligator").with(
method: :get,
path: '/alligators/Mary',
headers: {'Accept' => 'application/json'} ).
will_respond_with(status: 404)
end
it "returns nil" do
assert_equal(AnimalServiceClient.find_alligator_by_name("Mary"), nil)
end
end
describe "when an error occurs retrieving the alligator" do
before do
animal_service.given("an error occurs retrieving an alligator").
upon_receiving("a request for an alligator").with(
method: :get,
path: '/alligators/Mary',
headers: {'Accept' => 'application/json'}).
will_respond_with(
status: 500,
headers: { 'Content-Type' => 'application/json;charset=utf-8'},
body: {error: 'Argh!!!'})
end
it "raises an error" do
error = ->{ AnimalServiceClient.find_alligator_by_name("Mary") }.must_raise AnimalServiceError
error.message.must_match /Argh/
end
end
end
end
end