pact 1.1.0.rc2 → 1.1.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/.gitignore +0 -1
  2. data/CHANGELOG.md +46 -1
  3. data/Gemfile.lock +6 -4
  4. data/README.md +40 -186
  5. data/Rakefile +1 -1
  6. data/documentation/README.md +10 -0
  7. data/documentation/best-practices.md +33 -0
  8. data/documentation/configuration.md +166 -0
  9. data/documentation/diff_formatter_embedded.png +0 -0
  10. data/documentation/diff_formatter_list.png +0 -0
  11. data/documentation/diff_formatter_unix.png +0 -0
  12. data/documentation/faq.md +36 -6
  13. data/documentation/provider-states.md +173 -0
  14. data/documentation/raq.md +4 -4
  15. data/documentation/terminology.md +2 -2
  16. data/example/animal-service/Gemfile.lock +6 -9
  17. data/example/animal-service/Rakefile +2 -0
  18. data/example/animal-service/db/animal_db.sqlite3 +0 -0
  19. data/example/animal-service/lib/animal_service/animal_repository.rb +1 -5
  20. data/example/animal-service/lib/animal_service/api.rb +1 -1
  21. data/example/animal-service/spec/service_consumers/pact_helper.rb +7 -10
  22. data/example/animal-service/spec/service_consumers/provider_states_for_zoo_app.rb +5 -1
  23. data/example/zoo-app/Gemfile.lock +6 -9
  24. data/example/zoo-app/Rakefile +5 -0
  25. data/example/zoo-app/doc/markdown/README.md +3 -0
  26. data/example/zoo-app/doc/markdown/Zoo App - Animal Service.md +75 -0
  27. data/example/zoo-app/lib/zoo_app/animal_service_client.rb +2 -2
  28. data/example/zoo-app/spec/pacts/zoo_app-animal_service.json +1 -1
  29. data/example/zoo-app/spec/service_providers/animal_service_client_spec.rb +29 -34
  30. data/example/zoo-app/spec/service_providers/pact_helper.rb +4 -0
  31. data/lib/pact/configuration.rb +49 -1
  32. data/lib/pact/consumer/configuration.rb +4 -172
  33. data/lib/pact/consumer/configuration/configuration_extensions.rb +15 -0
  34. data/lib/pact/consumer/configuration/dsl.rb +12 -0
  35. data/lib/pact/consumer/configuration/mock_service.rb +89 -0
  36. data/lib/pact/consumer/configuration/service_consumer.rb +51 -0
  37. data/lib/pact/consumer/configuration/service_provider.rb +40 -0
  38. data/lib/pact/consumer/mock_service/interaction_mismatch.rb +3 -3
  39. data/lib/pact/consumer/mock_service/interaction_post.rb +2 -2
  40. data/lib/pact/consumer/mock_service/interaction_replay.rb +3 -4
  41. data/lib/pact/consumer/mock_service/verification_get.rb +32 -13
  42. data/lib/pact/consumer/rspec.rb +2 -4
  43. data/lib/pact/consumer/spec_hooks.rb +3 -1
  44. data/lib/pact/consumer_contract/consumer_contract.rb +1 -1
  45. data/lib/pact/consumer_contract/interaction.rb +1 -1
  46. data/lib/pact/doc/doc_file.rb +40 -0
  47. data/lib/pact/doc/generate.rb +11 -0
  48. data/lib/pact/doc/generator.rb +81 -0
  49. data/lib/pact/doc/interaction_view_model.rb +113 -0
  50. data/lib/pact/doc/markdown/generator.rb +26 -0
  51. data/lib/pact/doc/markdown/index_renderer.rb +41 -0
  52. data/lib/pact/doc/markdown/interaction.erb +14 -0
  53. data/lib/pact/doc/markdown/interaction_renderer.rb +38 -0
  54. data/lib/pact/doc/markdown/interactions_renderer.rb +56 -0
  55. data/lib/pact/doc/sort_interactions.rb +17 -0
  56. data/lib/pact/matchers/actual_type.rb +16 -0
  57. data/lib/pact/matchers/base_difference.rb +37 -0
  58. data/lib/pact/matchers/differ.rb +150 -0
  59. data/lib/pact/matchers/difference.rb +5 -30
  60. data/lib/pact/matchers/difference_indicator.rb +26 -0
  61. data/lib/pact/matchers/embedded_diff_formatter.rb +62 -0
  62. data/lib/pact/matchers/expected_type.rb +35 -0
  63. data/lib/pact/matchers/index_not_found.rb +3 -12
  64. data/lib/pact/matchers/{diff_decorator.rb → list_diff_formatter.rb} +28 -11
  65. data/lib/pact/matchers/matchers.rb +35 -39
  66. data/lib/pact/matchers/no_diff_indicator.rb +18 -0
  67. data/lib/pact/matchers/regexp_difference.rb +13 -0
  68. data/lib/pact/matchers/type_difference.rb +16 -0
  69. data/lib/pact/matchers/unexpected_index.rb +3 -13
  70. data/lib/pact/matchers/unexpected_key.rb +3 -12
  71. data/lib/pact/matchers/{plus_minus_diff_decorator.rb → unix_diff_formatter.rb} +22 -7
  72. data/lib/pact/provider/configuration.rb +5 -178
  73. data/lib/pact/provider/configuration/configuration_extension.rb +58 -0
  74. data/lib/pact/provider/configuration/dsl.rb +13 -0
  75. data/lib/pact/provider/configuration/pact_verification.rb +46 -0
  76. data/lib/pact/provider/configuration/service_provider_config.rb +16 -0
  77. data/lib/pact/provider/configuration/service_provider_dsl.rb +54 -0
  78. data/lib/pact/provider/matchers.rb +21 -13
  79. data/lib/pact/provider/matchers/messages.rb +43 -0
  80. data/lib/pact/provider/pact_spec_runner.rb +8 -0
  81. data/lib/pact/provider/rspec.rb +1 -1
  82. data/lib/pact/provider/rspec/formatter.rb +9 -7
  83. data/lib/pact/{consumer_contract → shared}/active_support_support.rb +4 -0
  84. data/lib/pact/shared/jruby_support.rb +18 -0
  85. data/lib/pact/shared/key_not_found.rb +3 -16
  86. data/lib/pact/shared/request.rb +5 -5
  87. data/lib/pact/term.rb +2 -2
  88. data/lib/pact/version.rb +1 -1
  89. data/pact.gemspec +2 -2
  90. data/spec/integration/pact/provider_configuration_spec.rb +2 -1
  91. data/spec/lib/pact/configuration_spec.rb +73 -0
  92. data/spec/lib/pact/consumer/mock_service/interaction_mismatch_spec.rb +21 -3
  93. data/spec/lib/pact/consumer/mock_service/verification_get_spec.rb +134 -0
  94. data/spec/lib/pact/consumer/request_spec.rb +1 -1
  95. data/spec/lib/pact/consumer_contract/active_support_support_spec.rb +1 -1
  96. data/spec/lib/pact/doc/generator_spec.rb +69 -0
  97. data/spec/lib/pact/doc/interaction_view_model_spec.rb +112 -0
  98. data/spec/lib/pact/doc/markdown/index_renderer_spec.rb +29 -0
  99. data/spec/lib/pact/doc/markdown/interactions_renderer_spec.rb +29 -0
  100. data/spec/lib/pact/matchers/differ_spec.rb +214 -0
  101. data/spec/lib/pact/matchers/difference_spec.rb +2 -12
  102. data/spec/lib/pact/matchers/embedded_diff_formatter_spec.rb +77 -0
  103. data/spec/lib/pact/matchers/index_not_found_spec.rb +21 -0
  104. data/spec/lib/pact/matchers/list_diff_formatter_spec.rb +114 -0
  105. data/spec/lib/pact/matchers/matchers_spec.rb +38 -22
  106. data/spec/lib/pact/matchers/regexp_difference_spec.rb +20 -0
  107. data/spec/lib/pact/matchers/type_difference_spec.rb +34 -0
  108. data/spec/lib/pact/matchers/unexpected_index_spec.rb +20 -0
  109. data/spec/lib/pact/matchers/unexpected_key_spec.rb +20 -0
  110. data/spec/lib/pact/matchers/{plus_minus_diff_decorator_spec.rb → unix_diff_formatter_spec.rb} +35 -6
  111. data/spec/lib/pact/provider/configuration/configuration_extension_spec.rb +30 -0
  112. data/spec/lib/pact/provider/configuration/pact_verification_spec.rb +43 -0
  113. data/spec/lib/pact/provider/configuration/service_provider_config_spec.rb +21 -0
  114. data/spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb +92 -0
  115. data/spec/lib/pact/provider/configuration_spec.rb +7 -150
  116. data/spec/lib/pact/provider/matchers/messages_spec.rb +104 -0
  117. data/spec/lib/pact/provider/rspec/formatter_spec.rb +56 -0
  118. data/spec/lib/pact/shared/key_not_found_spec.rb +20 -0
  119. data/spec/lib/pact/shared/request_spec.rb +28 -0
  120. data/spec/spec_helper.rb +3 -0
  121. data/spec/standalone/consumer_fail_test.rb +54 -0
  122. data/spec/standalone/consumer_pass_test.rb +50 -0
  123. data/spec/support/generated_index.md +4 -0
  124. data/spec/support/generated_markdown.md +55 -0
  125. data/spec/support/interaction_view_model.json +63 -0
  126. data/spec/support/markdown_pact.json +48 -0
  127. data/spec/support/pact_helper.rb +2 -1
  128. data/spec/support/spec_support.rb +7 -0
  129. data/spec/support/test_app_fail.json +11 -2
  130. data/tasks/pact-test.rake +9 -0
  131. metadata +113 -20
  132. data/example/animal-service/db/animals_db.sqlite3 +0 -0
  133. data/lib/pact/consumer/rspec/full_example_description.rb +0 -28
  134. data/lib/pact/matchers/nested_json_diff_decorator.rb +0 -53
  135. data/spec/lib/pact/matchers/diff_decorator_spec.rb +0 -80
  136. data/spec/lib/pact/matchers/nested_json_diff_decorator_spec.rb +0 -48
@@ -91,6 +91,14 @@ module Pact
91
91
  config.add_formatter Pact::Provider::RSpec::Formatter
92
92
  config.add_formatter Pact::Provider::RSpec::SilentJsonFormatter
93
93
 
94
+ config.before(:suite) do
95
+ # Preload app before suite so the classes loaded in memory are consistent for
96
+ # before :each and after :each hooks.
97
+ # Otherwise the app and all its dependencies are loaded between the first before :each
98
+ # and the first after :each, leading to inconsistent behaviour
99
+ # (eg. with database_cleaner transactions)
100
+ Pact.configuration.provider.app
101
+ end
94
102
  end
95
103
 
96
104
  def run_specs
@@ -109,7 +109,7 @@ module Pact
109
109
  expected_response['headers'].each do |name, expected_header_value|
110
110
  it "\"#{name}\" with value \"#{expected_header_value}\"" do
111
111
  header_value = response.headers[name]
112
- expect(header_value).to match_term expected_header_value
112
+ expect(header_value).to match_header(name, expected_header_value)
113
113
  end
114
114
  end
115
115
  end
@@ -1,12 +1,13 @@
1
1
  require 'pact/provider/print_missing_provider_states'
2
2
  require 'rspec/core/formatters'
3
- require 'colored'
3
+ require 'term/ansicolor'
4
4
 
5
5
  module Pact
6
6
  module Provider
7
7
  module RSpec
8
8
  class Formatter < ::RSpec::Core::Formatters::DocumentationFormatter
9
9
 
10
+ C = ::Term::ANSIColor
10
11
 
11
12
  def dump_commands_to_rerun_failed_examples
12
13
  return if failed_examples.empty?
@@ -17,9 +18,11 @@ module Pact
17
18
 
18
19
  end
19
20
 
21
+ private
22
+
20
23
  def print_rerun_commands
21
24
  output.puts("\n")
22
- interaction_failure_messages.each do | message |
25
+ interaction_rerun_commands.each do | message |
23
26
  output.puts(message)
24
27
  end
25
28
  end
@@ -28,13 +31,13 @@ module Pact
28
31
  PrintMissingProviderStates.call Pact.world.provider_states.missing_provider_states, output
29
32
  end
30
33
 
31
- def interaction_failure_messages
34
+ def interaction_rerun_commands
32
35
  failed_examples.collect do |example|
33
- interaction_failure_message_for example
36
+ interaction_rerun_command_for example
34
37
  end.uniq
35
38
  end
36
39
 
37
- def interaction_failure_message_for example
40
+ def interaction_rerun_command_for example
38
41
  provider_state = example.metadata[:pact_interaction].provider_state
39
42
  description = example.metadata[:pact_interaction].description
40
43
  pactfile_uri = example.metadata[:pactfile_uri]
@@ -47,8 +50,7 @@ module Pact
47
50
  end
48
51
 
49
52
  def failure_message
50
-
51
- "\n" + "For assistance debugging failures, please note:".underline.yellow + "\n\n" +
53
+ "\n" + C.underline(C.yellow("For assistance debugging failures, please note:")) + "\n\n" +
52
54
  "The pact files have been stored locally in the following temp directory:\n #{Pact.configuration.tmp_dir}\n\n" +
53
55
  "The requests and responses are logged in the following log file:\n #{Pact.configuration.log_path}\n\n"
54
56
  end
@@ -43,5 +43,9 @@ module Pact
43
43
  end
44
44
  end
45
45
 
46
+ def remove_unicode json
47
+ json.gsub(/\\u([0-9A-Za-z]{4})/) {|s| [$1.to_i(16)].pack("U")}
48
+ end
49
+
46
50
  end
47
51
  end
@@ -0,0 +1,18 @@
1
+ module Pact
2
+ module JRubySupport
3
+
4
+ # Under jruby, JSON.pretty_generate inserts a blank new line between the opening and closing
5
+ # brackets of an empty hash, like so:
6
+ # {
7
+ # "empty": {
8
+ #
9
+ # }
10
+ # }
11
+ # This screws up the UnixDiffFormatter, so we need to remove the blank lines.
12
+
13
+ def fix_blank_lines_in_empty_hashes json
14
+ json.gsub(/({\n)\n(\s*})/,'\1\2')
15
+ end
16
+
17
+ end
18
+ end
@@ -1,25 +1,12 @@
1
- module Pact
2
- class KeyNotFound
3
- def == other
4
- other.is_a? KeyNotFound
5
- end
1
+ require 'pact/matchers/difference_indicator'
6
2
 
7
- def eql? other
8
- self == other
9
- end
3
+ module Pact
4
+ class KeyNotFound < Pact::DifferenceIndicator
10
5
 
11
6
  def to_s
12
7
  "<key not found>"
13
8
  end
14
9
 
15
- def as_json options={}
16
- to_s
17
- end
18
-
19
- def to_json options = {}
20
- as_json.to_json options
21
- end
22
-
23
10
  def empty?
24
11
  true
25
12
  end
@@ -29,15 +29,15 @@ module Pact
29
29
  end
30
30
 
31
31
  def to_hash
32
- base_json = {
32
+ hash = {
33
33
  method: method,
34
34
  path: path,
35
35
  }
36
36
 
37
- base_json.merge!(body: body) unless body.is_a? self.class.key_not_found.class
38
- base_json.merge!(headers: headers) unless headers.is_a? self.class.key_not_found.class
39
- base_json.merge!(query: query) unless query.is_a? self.class.key_not_found.class
40
- base_json
37
+ hash.merge!(query: query) unless query.is_a? self.class.key_not_found.class
38
+ hash.merge!(headers: headers) unless headers.is_a? self.class.key_not_found.class
39
+ hash.merge!(body: body) unless body.is_a? self.class.key_not_found.class
40
+ hash
41
41
  end
42
42
 
43
43
  def method_and_path
data/lib/pact/term.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'pact/consumer_contract/active_support_support'
1
+ require 'pact/shared/active_support_support'
2
2
  require 'json/add/regexp'
3
3
 
4
4
  module Pact
@@ -43,7 +43,7 @@ module Pact
43
43
  end
44
44
 
45
45
  def to_s
46
- "Pact::Term matcher: #{matcher.to_s}" + (generate.nil? ? "" : " generate: \"#{generate}\"")
46
+ "Pact::Term matcher: #{matcher.inspect}" + (generate.nil? ? "" : " generate: \"#{generate}\"")
47
47
  end
48
48
 
49
49
  def diff_with_actual(actual)
data/lib/pact/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pact
2
- VERSION = "1.1.0.rc2"
2
+ VERSION = "1.1.0.rc3"
3
3
  end
data/pact.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["james.fraser@alumni.swinburne.edu", "sergei.matheson@gmail.com", "brent@fuglylogic.com", "uglyog@gmail.com", "bskurrie@dius.com.au"]
11
11
  gem.description = %q{Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.}
12
12
  gem.summary = %q{Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.}
13
- gem.homepage = "https://github.com/realestate-com-au/pact.git"
13
+ gem.homepage = "https://github.com/realestate-com-au/pact"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -26,7 +26,7 @@ Gem::Specification.new do |gem|
26
26
  gem.add_runtime_dependency 'thor'
27
27
  gem.add_runtime_dependency 'json' #Not locking down a version because buncher gem requires 1.6, while other projects use 1.7.
28
28
  gem.add_runtime_dependency 'webrick'
29
- gem.add_runtime_dependency 'colored'
29
+ gem.add_runtime_dependency 'term-ansicolor', '~> 1.0'
30
30
 
31
31
  gem.add_development_dependency 'rake', '~> 10.0.3'
32
32
  gem.add_development_dependency 'webmock', '~> 1.9.3'
@@ -9,11 +9,12 @@ describe "provider side" do
9
9
  end
10
10
 
11
11
  let(:application) { double("App")}
12
+
12
13
  before do
13
14
  app_block = ->{ application }
14
15
  Pact.service_provider "My Provider" do
15
16
  app &app_block
16
- end
17
+ end
17
18
  end
18
19
 
19
20
  it "makes the app available to the tests" do
@@ -19,10 +19,83 @@ describe Pact do
19
19
  expect(Pact.configuration.send(key)).to eql(value)
20
20
  end
21
21
  end
22
+
22
23
  end
23
24
 
24
25
  describe Pact::Configuration do
25
26
  let(:configuration) { Pact::Configuration.new }
27
+
28
+ describe "doc_generator" do
29
+
30
+ context "with a symbol" do
31
+ it "allows configuration of a doc_generator" do
32
+ Pact.configuration.doc_generator = :markdown
33
+ expect(Pact.configuration.doc_generators).to eq [Pact::Doc::Markdown::Generator]
34
+ end
35
+ end
36
+
37
+ context "with anything that responds to 'call'" do
38
+
39
+ it "allows configuration of a doc_generator" do
40
+ Pact.configuration.doc_generator = lambda { | pact_dir, doc_dir | "doc" }
41
+ expect(Pact.configuration.doc_generators.size).to be 1
42
+ expect(Pact.configuration.doc_generators.first.call('doc','pacts')).to eq ("doc")
43
+ end
44
+
45
+ end
46
+
47
+ context "with something that does not respond to call and doesn't have a matching doc_generator" do
48
+ it "raises an error" do
49
+ expect { Pact.configuration.doc_generator = Object.new }.to raise_error "Pact.configuration.doc_generator needs to respond to call, or be in the preconfigured list: [:markdown]"
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ describe "#diff_formatter" do
56
+
57
+ let(:subject) { Pact::Configuration.new }
58
+
59
+ it "returns the Pact::Matchers::UnixDiffFormatter by default" do
60
+ expect(subject.diff_formatter).to eq(Pact::Matchers::UnixDiffFormatter)
61
+ end
62
+
63
+ Pact::Configuration::DIFF_FORMATTERS.each_pair do | key, diff_formatter |
64
+
65
+ context "when set to :#{key}" do
66
+
67
+ before do
68
+ subject.diff_formatter = key
69
+ end
70
+
71
+ it "sets the diff_formatter to #{diff_formatter}" do
72
+ expect(subject.diff_formatter).to be diff_formatter
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ context "when set to an object that responds to call" do
79
+
80
+ let(:diff_formatter) { lambda{ | diff| } }
81
+
82
+ before do
83
+ subject.diff_formatter = diff_formatter
84
+ end
85
+
86
+ it "sets the diff_formatter to the object" do
87
+ expect(subject.diff_formatter).to be diff_formatter
88
+ end
89
+ end
90
+
91
+ context "when set to an object that does not respond to call and isn't a known default option" do
92
+ it "raises an error" do
93
+ expect { subject.diff_formatter = Object.new }.to raise_error "Pact.configuration.diff_formatter needs to respond to call, or be in the preconfigured list: [:embedded, :unix, :list]"
94
+ end
95
+ end
96
+
97
+ end
98
+
26
99
  describe "pactfile_write_mode" do
27
100
  context "when @pactfile_write_mode is :overwrite" do
28
101
  it 'returns :overwrite' do
@@ -7,11 +7,11 @@ module Pact
7
7
  let(:actual_request) { instance_double('Pact::Consumer::Request::Actual', :method_and_path => 'GET /path') }
8
8
  let(:expected_request_1) { instance_double('Pact::Request::Expected') }
9
9
  let(:expected_request_2) { instance_double('Pact::Request::Expected') }
10
- let(:candidate_1) { instance_double('Pact::Interaction', request: expected_request_1) }
11
- let(:candidate_2) { instance_double('Pact::Interaction', request: expected_request_2) }
10
+ let(:candidate_1) { instance_double('Pact::Interaction', request: expected_request_1, description_with_provider_state_quoted: "desc 1") }
11
+ let(:candidate_2) { instance_double('Pact::Interaction', request: expected_request_2, description_with_provider_state_quoted: "desc 2") }
12
12
  let(:candidate_interactions) { [candidate_1, candidate_2] }
13
13
  subject { InteractionMismatch.new(candidate_interactions, actual_request) }
14
- let(:diff_1) { {body: nil} }
14
+ let(:diff_1) { {body: 'diff'} }
15
15
  let(:diff_2) { {} }
16
16
 
17
17
  before do
@@ -44,6 +44,24 @@ module Pact
44
44
  end
45
45
  end
46
46
  end
47
+
48
+ describe "to_s" do
49
+ let(:expected_message) { "Diff with interaction: desc 1\ndiff 1\nDiff with interaction: desc 2\ndiff 2" }
50
+
51
+ before do
52
+ allow(Pact.configuration.diff_formatter).to receive(:call).and_return("diff 1", "diff 2")
53
+ end
54
+
55
+ it "creates diff output using the configured diff_formatter" do
56
+ expect(Pact.configuration.diff_formatter).to receive(:call).with(diff_1, colour: false)
57
+ expect(Pact.configuration.diff_formatter).to receive(:call).with(diff_2, colour: false)
58
+ subject.to_s
59
+ end
60
+
61
+ it "includes a diff output in the string output" do
62
+ expect(subject.to_s).to eq expected_message
63
+ end
64
+ end
47
65
  end
48
66
  end
49
67
  end
@@ -0,0 +1,134 @@
1
+ require 'spec_helper'
2
+ require 'pact/consumer/mock_service/verification_get'
3
+
4
+ module Pact
5
+ module Consumer
6
+ describe VerificationGet do
7
+
8
+ let(:interaction_list) { instance_double("Pact::Consumer::InteractionList")}
9
+ let(:logger) { double("Logger").as_null_object }
10
+ let(:log_description) { "/log/pact.log" }
11
+
12
+ subject { VerificationGet.new('VerificationGet', logger, interaction_list, log_description) }
13
+
14
+ its(:request_path) { should eq '/verify'}
15
+ its(:request_method) { should eq 'GET'}
16
+
17
+
18
+ describe "#respond" do
19
+ let(:env) { {
20
+ "QUERY_STRING" => "example_description=a description"
21
+ } }
22
+
23
+ before do
24
+ allow(interaction_list).to receive(:all_matched?).and_return(all_matched)
25
+ end
26
+
27
+ let(:response) { subject.respond env }
28
+
29
+ context "when all interactions have been matched" do
30
+ let(:all_matched) { true }
31
+
32
+ it "returns a 200 status" do
33
+ expect(response.first).to eq 200
34
+ end
35
+
36
+ it "returns a Content-Type of text/plain" do
37
+ expect(response[1]).to eq 'Content-Type' => 'text/plain'
38
+ end
39
+
40
+ it "returns a nice message" do
41
+ expect(response.last).to eq ['Interactions matched']
42
+ end
43
+
44
+ it "logs the success" do
45
+ expect(logger).to receive(:info).with(/Verifying - interactions matched.*a description/)
46
+ response
47
+ end
48
+ end
49
+
50
+ context "when all interactions not been matched" do
51
+ let(:all_matched) { false }
52
+ let(:failure_message) { "this is a failure message"}
53
+
54
+ before do
55
+ allow_any_instance_of(VerificationGet::FailureMessage).to receive(:to_s).and_return(failure_message)
56
+ end
57
+
58
+ it "returns a 500 status" do
59
+ expect(response.first).to eq 500
60
+ end
61
+
62
+ it "returns a Content-Type of text/plain" do
63
+ expect(response[1]).to eq 'Content-Type' => 'text/plain'
64
+ end
65
+
66
+ it "returns a message" do
67
+ expect(response.last.first).to include "Actual interactions do not match"
68
+ expect(response.last.first).to include failure_message
69
+ expect(response.last.first).to include log_description
70
+ end
71
+
72
+ it "logs the failure message" do
73
+ expect(logger).to receive(:warn).with(/Verifying - actual interactions do not match/)
74
+ expect(logger).to receive(:warn).with(failure_message)
75
+ response
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+
82
+ describe "FailureMessage" do
83
+ let(:missing_interactions_summaries) { ["Blah", "Thing"]}
84
+ let(:interaction_mismatches_summaries) { []}
85
+ let(:unexpected_requests_summaries) { []}
86
+ let(:interaction_list) { instance_double("Pact::Consumer::InteractionList") }
87
+ subject { VerificationGet::FailureMessage.new(interaction_list).to_s }
88
+
89
+ before do
90
+ allow(interaction_list).to receive(:missing_interactions_summaries).and_return(missing_interactions_summaries)
91
+ allow(interaction_list).to receive(:interaction_mismatches_summaries).and_return(interaction_mismatches_summaries)
92
+ allow(interaction_list).to receive(:unexpected_requests_summaries).and_return(unexpected_requests_summaries)
93
+ end
94
+
95
+ context "with only a missing interactions" do
96
+
97
+ let(:expected_string) { <<-EOS
98
+ Missing requests:
99
+ \tBlah
100
+ \tThing
101
+
102
+ EOS
103
+ }
104
+ it "only includes missing interactions" do
105
+ expect(subject).to eq expected_string
106
+ end
107
+ end
108
+
109
+ context "with missing, mismatches and unexpected interactions" do
110
+
111
+ let(:interaction_mismatches_summaries) { ["wiffle"]}
112
+ let(:unexpected_requests_summaries) { ["moose"]}
113
+
114
+ let(:expected_string) { <<-EOS
115
+ Incorrect requests:
116
+ \twiffle
117
+
118
+ Missing requests:
119
+ \tBlah
120
+ \tThing
121
+
122
+ Unexpected requests:
123
+ \tmoose
124
+
125
+ EOS
126
+ }
127
+ it "includes all the things" do
128
+ expect(subject).to eq expected_string
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end