Sha256: 5b08ef976f1530873012973243520780528ebf5f9e9b600631c11af042ad8a0c

Contents?: true

Size: 946 Bytes

Versions: 23

Compression:

Stored size: 946 Bytes

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Praxis::Handlers::JSON do
  let(:dictionary) { { 'foo' => 1 } }
  let(:dictionary_json) { '{"foo":1}' }

  let(:array) { [1, 2, 3] }
  let(:array_json) { '[1,2,3]' }

  describe '#parse' do
    it 'handles dictionaries' do
      expect(subject.parse(dictionary_json)).to eq(dictionary)
    end

    it 'handles arrays' do
      expect(subject.parse(array_json)).to eq(array)
    end
  end

  # slightly cheesy: use #parse to test #generate by round-tripping everything
  describe '#generate' do
    it 'pretty-prints' do
      result = subject.generate({ 'foo' => 1 })
      expect(result).to include("\n")
      expect(result).to match(/^  /m)
    end

    it 'handles dictionaries' do
      expect(subject.parse(subject.generate(dictionary))).to eq(dictionary)
    end

    it 'handles arrays' do
      expect(subject.parse(subject.generate(array))).to eq(array)
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
praxis-2.0.0 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.40 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.39 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.38 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.37 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.36 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.35 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.34 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.33 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.32 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.31 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.30 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.29 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.28 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.27 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.26 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.25 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.24 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.23 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.22 spec/praxis/handlers/json_spec.rb