Sha256: 2def4e3ceb2bd94d3b3976d484753f2dc92866baca6d2a6b9eca0176d0456ed0

Contents?: true

Size: 909 Bytes

Versions: 31

Compression:

Stored size: 909 Bytes

Contents

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

31 entries across 31 versions & 1 rubygems

Version Path
praxis-2.0.pre.18 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.17 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.16 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.15 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.14 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.13 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.12 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.11 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.10 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.9 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.8 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.7 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.6 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.5 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.4 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.3 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.2 spec/praxis/handlers/json_spec.rb
praxis-2.0.pre.1 spec/praxis/handlers/json_spec.rb
praxis-0.22.pre.2 spec/praxis/handlers/json_spec.rb
praxis-0.22.pre.1 spec/praxis/handlers/json_spec.rb