summaryrefslogtreecommitdiff
path: root/spec/support/matchers/be_valid_json.rb
blob: 228c1fc986ea5c53bc1279d83379c27bac5433ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# frozen_string_literal: true

RSpec::Matchers.define :be_valid_json do
  match do |actual|
    Gitlab::Json.parse(actual).present?
  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