debian-mirror-gitlab/spec/support/matchers/be_valid_json.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

19 lines
342 B
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
RSpec::Matchers.define :be_valid_json do
match do |actual|
2021-03-08 18:12:59 +05:30
Gitlab::Json.parse(actual).present?
2021-02-22 17:27:13 +05:30
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