Sha256: 63b9a02fb2970a4c713a6619f6808af5e568669bcafbc68cb24978f787cd733e

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

require 'spec_helper'
describe ::ArJsonSerialize::Serializer do
  %w(dump load).each do |k|
    it { should respond_to(k.to_sym) }
  end

  context '#load' do
    it 'should call MultiJson.load' do
      expect(::MultiJson).to receive(:load).with('string')
      subject.load('string')
    end

    [nil, ''].each do |k|
      it "should not call MultiJson.load if string is #{k.inspect}" do
        expect(::MultiJson).not_to receive(:load)
        subject.load(k)
      end

      it "should return empty if string is #{k.inspect}" do
        expect(subject.load(k)).to eq('')
      end

    end

    context 'content is' do
      subject { ::ArJsonSerialize::Serializer.load(data) }

      context 'String "foo"' do
        let(:data) { '"foo"' }
        it { should be_a(::String) }
        it { should == 'foo' }
      end

      context 'Hash {"key1":"value1"}' do
        let(:data) { '{"key1":"value1"}' }
        it { should be_a(::Hashie::Mash) }
        it { should == {'key1' => 'value1'} }

        describe '#key1' do
          subject { super().key1 }
          it { should == 'value1' }
        end
      end

      context 'Array' do
        context '["1", "2", "3"]' do
          let(:data) { '["1","2","3"]' }
          it { should be_a(::Array) }
          it { should == %w(1 2 3)}
        end

        context '["1","2","3",{"key1":"value1"}]' do
          let(:data) { '["1","2","3",{"key1":"value1"}]' }
          it { should be_a(::Array) }
          it { should == ['1', '2', '3', {"key1"=>"value1"}] }

          describe '#last' do
            subject { super().last }
            it { should be_a(::Hashie::Mash) }
          end
        end

      end

    end

  end

  context '#dump' do
    it 'should call MultiJson.dump' do
      expect(::MultiJson).to receive(:dump).with('foo')
      subject.dump('foo')
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ar_json_serialize-0.0.3 spec/ar_json_serialize/serializer_spec.rb