File tree 4 files changed +50
-2
lines changed
lib/pact/consumer_contract
4 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ def self.from_hash(hash)
37
37
elsif hash [ :messages ]
38
38
hash [ :messages ] . collect { |hash | Message . from_hash ( hash ) }
39
39
else
40
- [ ]
40
+ [ ] # or raise an error?
41
41
end
42
42
43
43
new (
Original file line number Diff line number Diff line change @@ -36,6 +36,14 @@ def to_hash
36
36
}
37
37
end
38
38
39
+ def http?
40
+ true
41
+ end
42
+
43
+ def message?
44
+ false
45
+ end
46
+
39
47
def validate!
40
48
raise Pact ::InvalidInteractionError . new ( self ) unless description && request && response
41
49
end
Original file line number Diff line number Diff line change 3
3
require 'pact/shared/active_support_support'
4
4
require 'pact/matching_rules'
5
5
require 'pact/errors'
6
+ require 'pact/consumer/request'
7
+ require 'pact/consumer_contract/response'
6
8
7
9
module Pact
8
10
class Message
@@ -13,8 +15,8 @@ class Message
13
15
14
16
def initialize attributes = { }
15
17
@description = attributes [ :description ]
16
- @request = attributes [ :content ]
17
18
@provider_state = attributes [ :provider_state ] || attributes [ :providerState ]
19
+ @content = attributes [ :content ]
18
20
end
19
21
20
22
def self . from_hash hash
@@ -31,6 +33,41 @@ def to_hash
31
33
}
32
34
end
33
35
36
+
37
+ def request
38
+ @request ||= Pact ::Consumer ::Request ::Actual . from_hash (
39
+ path : '/' ,
40
+ method : 'POST' ,
41
+ query : nil ,
42
+ headers : { 'Content-Type' => 'application/json' } ,
43
+ body : {
44
+ description : description ,
45
+ providerStates : [ {
46
+ name : provider_state
47
+ } ]
48
+ }
49
+ )
50
+ end
51
+
52
+ # custom media type?
53
+ def response
54
+ @response ||= Pact ::Response . new (
55
+ status : 200 ,
56
+ headers : { 'Content-Type' => 'application/json' } ,
57
+ body : {
58
+ content : content
59
+ }
60
+ )
61
+ end
62
+
63
+ def http?
64
+ false
65
+ end
66
+
67
+ def message?
68
+ true
69
+ end
70
+
34
71
def validate!
35
72
raise Pact ::InvalidMessageError . new ( self ) unless description && content
36
73
end
Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ class Content < Hash
4
4
include ActiveSupportSupport
5
5
include SymbolizeKeys
6
6
7
+ def initialize hash
8
+ merge! ( hash )
9
+ end
7
10
end
8
11
end
9
12
end
You can’t perform that action at this time.
0 commit comments