2020-12-09 16:09:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec::Matchers.define :be_valid_json do
|
|
|
|
match do |actual|
|
2021-01-06 13:10:52 -05:00
|
|
|
Gitlab::Json.parse(actual).present?
|
2020-12-09 16:09:43 -05:00
|
|
|
rescue JSON::ParserError => e
|
|
|
|
@error = e
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def failure_message
|
|
|
|
if @error
|
|
|
|
"Parse failed with error: #{@error}"
|
|
|
|
else
|
|
|
|
"Parsing did not return any data"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|