File: json_parser_spec.rb

package info (click to toggle)
ruby-prometheus-client-mmap 1.2.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 700 kB
  • sloc: ruby: 3,149; sh: 54; makefile: 21
file content (32 lines) | stat: -rw-r--r-- 753 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'spec_helper'
require 'oj'
require 'prometheus/client/helper/json_parser'

describe Prometheus::Client::Helper::JsonParser do
  describe '.load' do
    let(:input) { %({ "a": 1 }) }

    shared_examples 'JSON parser' do
      it 'parses JSON' do
        expect(described_class.load(input)).to eq({ 'a' => 1 })
      end

      it 'raises JSON::ParserError' do
        expect { described_class.load("{false}") }.to raise_error(JSON::ParserError)
      end
    end

    context 'with Oj' do
      it_behaves_like 'JSON parser'
    end

    context 'without Oj' do
      before(:all) do
        Object.send(:remove_const, 'Oj')
        load "prometheus/client/helper/json_parser.rb"
      end

      it_behaves_like 'JSON parser'
    end
  end
end