Skip to content

Commit

Permalink
chore: recreating issue for pact-ruby-standalone 10
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Feb 7, 2018
1 parent 5e91a38 commit 0b23d39
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 21 deletions.
9 changes: 5 additions & 4 deletions consumer/spec/bar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
bar_service.
upon_receiving("a retrieve thing request").with({
method: :get,
path: '/thing',
path: '/foo',
headers: {'Accept' => 'application/json'}
}).
will_respond_with({
status: 200,
headers: { 'Content-Type' => 'application/json' },
body: {
company: Pact.like("My big company"),
factories: Pact.each_like(location: "Sydney", capacity: 5)
results: Pact.each_like(
name: Pact.term("Games", /Games|Book Clubs/)
)
}
})

# This request would normally be performed some BarClient class,
# but just use simple request for the purposes of this test
bar_response = Faraday.get(bar_service.mock_service_base_url + "/thing", nil, {'Accept' => 'application/json'})
bar_response = Faraday.get(bar_service.mock_service_base_url + "/foo", nil, {'Accept' => 'application/json'})

# This would normally be checking the results of some deserialisation process,
# (eg. check for an array of Factory classes )
Expand Down
19 changes: 9 additions & 10 deletions consumer/spec/pacts/foo-bar.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"description": "a retrieve thing request",
"request": {
"method": "get",
"path": "/thing",
"path": "/foo",
"headers": {
"Accept": "application/json"
}
Expand All @@ -21,23 +21,22 @@
"Content-Type": "application/json"
},
"body": {
"company": "My big company",
"factories": [
"results": [
{
"location": "Sydney",
"capacity": 5
"name": "Games"
}
]
},
"matchingRules": {
"$.body.company": {
"match": "type"
},
"$.body.factories": {
"$.body.results": {
"min": 1
},
"$.body.factories[*].*": {
"$.body.results[*].*": {
"match": "type"
},
"$.body.results[*].name": {
"match": "regex",
"regex": "Games|Book Clubs"
}
}
}
Expand Down
76 changes: 76 additions & 0 deletions log/bar_mock_service.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
I, [2018-02-07T13:37:06.144957 #96803] INFO -- : Cleared interactions before example "BarClient can retrieve a thing"
I, [2018-02-07T13:37:06.148124 #96803] INFO -- : Registered expected interaction GET /foo
D, [2018-02-07T13:37:06.148259 #96803] DEBUG -- : {
"description": "a retrieve thing request",
"request": {
"method": "get",
"path": "/foo",
"headers": {
"Accept": "application/json"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"results": {
"json_class": "Pact::ArrayLike",
"contents": {
"name": {
"json_class": "Pact::Term",
"data": {
"generate": "Games",
"matcher": {"json_class":"Regexp","o":0,"s":"Games|Book Clubs"}
}
}
},
"min": 1
}
}
}
}
I, [2018-02-07T13:37:06.173082 #96803] INFO -- : Received request GET /foo
D, [2018-02-07T13:37:06.173183 #96803] DEBUG -- : {
"path": "/foo",
"query": "",
"method": "get",
"headers": {
"User-Agent": "Faraday v0.12.2",
"Accept": "application/json",
"Accept-Encoding": "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
"Connection": "close",
"Host": "localhost:4638",
"Version": "HTTP/1.1"
}
}
I, [2018-02-07T13:37:06.173341 #96803] INFO -- : Found matching response for GET /foo
D, [2018-02-07T13:37:06.173454 #96803] DEBUG -- : {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"results": {
"json_class": "Pact::ArrayLike",
"contents": {
"name": {
"json_class": "Pact::Term",
"data": {
"generate": "Games",
"matcher": {
"json_class": "Regexp",
"o": 0,
"s": "Games|Book Clubs"
}
}
}
},
"min": 1
}
}
}
I, [2018-02-07T13:37:06.177059 #96803] INFO -- : Verifying - interactions matched for example "BarClient can retrieve a thing"
I, [2018-02-07T13:37:06.181861 #96803] INFO -- : Writing pact with details {:consumer=>{:name=>"Foo"}, :provider=>{:name=>"Bar"}, :pactfile_write_mode=>"overwrite", :pact_dir=>"/Users/bethanyskurrie/workspace/pact-foundation/pact-ruby-e2e-example/consumer/spec/pacts"}
I, [2018-02-07T13:37:06.181970 #96803] INFO -- : Writing pact for Bar to /Users/bethanyskurrie/workspace/pact-foundation/pact-ruby-e2e-example/consumer/spec/pacts/foo-bar.json
16 changes: 16 additions & 0 deletions log/pact.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Logfile created on 2018-02-07 13:36:53 +1100 by logger.rb/56815
I, [2018-02-07T13:36:53.489916 #96786] INFO -- : Starting app Bar #<Pact::MockService::App:0x007fd64634fd40> on port 4638...
I, [2018-02-07T13:36:53.847858 #96786] INFO -- : Started on port 4638
I, [2018-02-07T13:36:54.021857 #96786] INFO -- : Clearing all expectations
I, [2018-02-07T13:36:54.070265 #96786] INFO -- : Verifying interactions for BarClient can retrieve a thing
D, [2018-02-07T13:36:54.077438 #96786] DEBUG -- : Supposed to be stopping
I, [2018-02-07T13:37:05.992080 #96803] INFO -- : Starting app Bar #<Pact::MockService::App:0x007febb6c85010> on port 4638...
I, [2018-02-07T13:37:06.108727 #96803] INFO -- : Started on port 4638
I, [2018-02-07T13:37:06.142151 #96803] INFO -- : Clearing all expectations
I, [2018-02-07T13:37:06.174394 #96803] INFO -- : Verifying interactions for BarClient can retrieve a thing
D, [2018-02-07T13:37:06.183443 #96803] DEBUG -- : Supposed to be stopping
I, [2018-02-07T13:37:06.859092 #96807] INFO -- : Running example 'Verifying a pact between Foo and Bar A retrieve thing request with GET /foo returns a response which has status code 200'
I, [2018-02-07T13:37:06.859217 #96807] INFO -- : Sending GET request to path: "/foo" with headers: {"HTTP_ACCEPT"=>"application/json"}, see debug logs for body
D, [2018-02-07T13:37:06.859245 #96807] DEBUG -- : body :
I, [2018-02-07T13:37:06.876198 #96807] INFO -- : Received response with status: 200, headers: {"Content-Type"=>"application/json", "Content-Length"=>"158"}, see debug logs for body
D, [2018-02-07T13:37:06.876249 #96807] DEBUG -- : body: {"results":[{"name":"Games","sort_name":"Games","id":11,"shortname":"Games"},{"name":"Book Clubs","sort_name":"Book Clubs","id":18,"shortname":"Book Clubs"}]}
16 changes: 9 additions & 7 deletions provider/bar_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ def call env
status = 200
headers = {'Content-Type' => 'application/json'}
body = {
"company": "My Company",
"factories": [
"results": [
{
"location": "Sydney",
"capacity": 5
"name": "Games",
"sort_name": "Games",
"id": 11,
"shortname": "Games"
},
{
"location": "Sydney",
"geographicCoords": "-0.145,1.4445",
"capacity": 5,
"name": "Book Clubs",
"sort_name": "Book Clubs",
"id": 18,
"shortname": "Book Clubs"
}
]
}.to_json
Expand Down
24 changes: 24 additions & 0 deletions provider/reports/help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# For assistance debugging failures

* The pact files have been stored locally in the following temp directory:
/Users/bethanyskurrie/workspace/pact-foundation/pact-ruby-e2e-example/tmp/pacts

* The requests and responses are logged in the following log file:
/Users/bethanyskurrie/workspace/pact-foundation/pact-ruby-e2e-example/log/pact.log

* Add BACKTRACE=true to the `rake pact:verify` command to see the full backtrace

* If the diff output is confusing, try using another diff formatter.
The options are :unix, :embedded and :list

Pact.configure do | config |
config.diff_formatter = :embedded
end

See https://github.com/realestate-com-au/pact/blob/master/documentation/configuration.md#diff_formatter for examples and more information.

* Check out https://github.com/realestate-com-au/pact/wiki/Troubleshooting

* Ask a question in the google users' group https://groups.google.com/forum/#!forum/pact-support


15 changes: 15 additions & 0 deletions spec/support/monkeypatch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
puts "MONKEYPATCHING!"

This comment has been minimized.

Copy link
@bethesque

bethesque Feb 7, 2018

Author Member

Sorry, ignore this. Accidental commit.


class PreMonkeypatchTest
include Pact::Consumer::RackRequestHelper
end

unless PreMonkeypatchTest.new.respond_to?(:standardise_header, true)
raise "Can't find method Pact::Consumer::RackRequestHelper.standardise_header to monkeypatch"
end

module Pact::Consumer::RackRequestHelper
def standardise_header header
header.gsub(/^HTTP_/, '').downcase
end
end

0 comments on commit 0b23d39

Please sign in to comment.