File tree 2 files changed +38
-3
lines changed
spec/lib/pact/consumer_contract
2 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -66,9 +66,9 @@ def warn_about_regexp(thing)
66
66
private
67
67
68
68
def fix_empty_hash_and_array json
69
- json = json . gsub ( /({\s *})/ , "{\n }" )
70
- json . gsub ( /\[ \s *\] / , "[\n ]" )
71
69
json
70
+ . gsub ( /({\s *})(?=,?$)/ , "{\n }" )
71
+ . gsub ( /\[ \s *\] (?=,?$)/ , "[\n ]" )
72
72
end
73
73
end
74
74
end
Original file line number Diff line number Diff line change @@ -77,6 +77,41 @@ def initialize
77
77
it "pretty formats the json that has been not pretty formatted because of ActiveSupport" do
78
78
expect ( fix_json_formatting ( active_support_affected_pretty_generated_json ) ) . to eq ( pretty_generated_json . strip )
79
79
end
80
+
81
+ context 'when the JSON includes empty arrays or hashes in a compact format' do
82
+ let ( :active_support_affected_pretty_generated_json ) do
83
+ '{
84
+ "empty_hash": {},
85
+ "empty_array": []
86
+ }'
87
+ end
88
+ let ( :pretty_generated_json ) do
89
+ '{
90
+ "empty_hash": {
91
+ },
92
+ "empty_array": [
93
+ ]
94
+ }'
95
+ end
96
+
97
+ it "expands the empty hash/array to be multiline" do
98
+ expect ( fix_json_formatting ( active_support_affected_pretty_generated_json ) ) . to eq ( pretty_generated_json . strip )
99
+ end
100
+ end
101
+
102
+ context 'when the JSON includes json-like strings inside' do
103
+ let ( :pretty_generated_json ) do
104
+ '{
105
+ "not_really_an_empty_hash": "{}",
106
+ "not_really_an_empty_array": "[]"
107
+ }'
108
+ end
109
+
110
+ it 'does not change the inner strings' do
111
+ expect ( fix_json_formatting ( pretty_generated_json ) ) . to eq ( pretty_generated_json )
112
+ end
113
+
114
+ end
80
115
end
81
116
end
82
- end
117
+ end
You can’t perform that action at this time.
0 commit comments