@@ -77,31 +77,52 @@ def describe_interaction interaction, options
77
77
78
78
describe description_for ( interaction ) , metadata do
79
79
80
- describe "with #{ interaction . request . method_and_path } " do
81
-
82
- interaction_context = InteractionContext . new
83
-
84
- before do | example |
85
- interaction_context . run_once :before do
86
- Pact . configuration . logger . info "Running example '#{ Pact ::RSpec . full_description ( example ) } '"
87
- set_up_provider_state interaction . provider_state , options [ :consumer ]
88
- replay_interaction interaction
89
- interaction_context . last_response = last_response
90
- end
80
+ interaction_context = InteractionContext . new
81
+
82
+ before do | example |
83
+ interaction_context . run_once :before do
84
+ Pact . configuration . logger . info "Running example '#{ Pact ::RSpec . full_description ( example ) } '"
85
+ set_up_provider_state interaction . provider_state , options [ :consumer ]
86
+ replay_interaction interaction
87
+ interaction_context . last_response = last_response
91
88
end
89
+ end
92
90
93
- after do
94
- interaction_context . run_once :after do
95
- tear_down_provider_state interaction . provider_state , options [ :consumer ]
96
- end
91
+ after do
92
+ interaction_context . run_once :after do
93
+ tear_down_provider_state interaction . provider_state , options [ :consumer ]
97
94
end
98
-
99
- describe_response Pact ::Response . new ( interaction . response ) , interaction_context
100
-
101
95
end
102
96
97
+ if interaction . respond_to? ( :message? ) && interaction . message?
98
+ describe_message Pact ::Response . new ( interaction . response ) , interaction_context
99
+ else
100
+ describe "with #{ interaction . request . method_and_path } " do
101
+ describe_response Pact ::Response . new ( interaction . response ) , interaction_context
102
+ end
103
+ end
103
104
end
105
+ end
104
106
107
+ def describe_message expected_response , interaction_context
108
+ include Pact ::RSpec ::Matchers
109
+ extend Pact ::Matchers ::Messages
110
+
111
+ let ( :expected_content ) { expected_response . body [ :content ] }
112
+ let ( :response ) { interaction_context . last_response }
113
+ let ( :differ ) { Pact . configuration . body_differ_for_content_type diff_content_type }
114
+ let ( :diff_formatter ) { Pact . configuration . diff_formatter_for_content_type diff_content_type }
115
+ let ( :diff_options ) { { with : differ , diff_formatter : diff_formatter } }
116
+ let ( :diff_content_type ) { 'application/json' }
117
+ let ( :response_body ) { parse_body_from_response ( response ) }
118
+ let ( :actual_content ) { response_body [ 'content' ] }
119
+
120
+ it "has matching content" do
121
+ if response . status != 200
122
+ raise "An error was raised while verifying the message. The response body is: #{ response . body } "
123
+ end
124
+ expect ( actual_content ) . to match_term expected_content , diff_options
125
+ end
105
126
end
106
127
107
128
def describe_response expected_response , interaction_context
0 commit comments