Class: Pact::MockService::Client
- Inherits:
-
Object
- Object
- Pact::MockService::Client
- Defined in:
- lib/pact/mock_service/client.rb
Constant Summary collapse
- MOCK_SERVICE_ADMINISTRATON_HEADERS =
{'X-Pact-Mock-Service' => 'true'}
Class Method Summary collapse
Instance Method Summary collapse
- #add_expected_interaction(interaction) ⇒ Object
- #clear_interactions(example_description) ⇒ Object
-
#initialize(port) ⇒ Client
constructor
A new instance of Client.
- #log(msg) ⇒ Object
- #verify(example_description) ⇒ Object
- #wait_for_interactions(wait_max_seconds, poll_interval) ⇒ Object
- #write_pact(pacticipant_details) ⇒ Object
Constructor Details
#initialize(port) ⇒ Client
Returns a new instance of Client.
10 11 12 |
# File 'lib/pact/mock_service/client.rb', line 10 def initialize port @http = Net::HTTP.new('localhost', port) end |
Class Method Details
.clear_interactions(port, example_description) ⇒ Object
43 44 45 |
# File 'lib/pact/mock_service/client.rb', line 43 def self.clear_interactions port, example_description Net::HTTP.new("localhost", port).delete("/interactions?example_description=#{CGI.escape(example_description)}", MOCK_SERVICE_ADMINISTRATON_HEADERS) end |
Instance Method Details
#add_expected_interaction(interaction) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/pact/mock_service/client.rb', line 34 def add_expected_interaction interaction response = http.request_post( '/interactions', interaction_json(interaction), MOCK_SERVICE_ADMINISTRATON_HEADERS.merge("Content-Type" => "application/json") ) raise "\e[31m#{response.body}\e[m" unless response.is_a? Net::HTTPSuccess end |
#clear_interactions(example_description) ⇒ Object
30 31 32 |
# File 'lib/pact/mock_service/client.rb', line 30 def clear_interactions example_description http.delete("/interactions?example_description=#{CGI.escape(example_description)}", MOCK_SERVICE_ADMINISTRATON_HEADERS) end |
#log(msg) ⇒ Object
19 20 21 |
# File 'lib/pact/mock_service/client.rb', line 19 def log msg http.request_get("/log?msg=#{CGI.escape(msg)}", MOCK_SERVICE_ADMINISTRATON_HEADERS) end |
#verify(example_description) ⇒ Object
14 15 16 17 |
# File 'lib/pact/mock_service/client.rb', line 14 def verify example_description response = http.request_get("/interactions/verification?example_description=#{CGI.escape(example_description)}", MOCK_SERVICE_ADMINISTRATON_HEADERS) raise "\e[31m#{response.body}\e[m" unless response.is_a? Net::HTTPSuccess end |
#wait_for_interactions(wait_max_seconds, poll_interval) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/pact/mock_service/client.rb', line 23 def wait_for_interactions wait_max_seconds, poll_interval wait_until_true(wait_max_seconds, poll_interval) do response = http.request_get("/interactions/missing", MOCK_SERVICE_ADMINISTRATON_HEADERS) JSON.parse(response.body)['size'] == 0 end end |
#write_pact(pacticipant_details) ⇒ Object
47 48 49 50 51 |
# File 'lib/pact/mock_service/client.rb', line 47 def write_pact pacticipant_details response = http.request_post("/pact", pacticipant_details.to_json, MOCK_SERVICE_ADMINISTRATON_HEADERS.merge("Content-Type" => "application/json")) raise "\e[31m#{response.body}\e[m" unless response.is_a? Net::HTTPSuccess response.body end |