Sha256: 78eadc6a3b51e9cfd14ff5d1f557b9b0ac005d0a25ff2cf672c2827417525295

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'
require 'thrift/types/value'
require 'thrift/types/known/any'

describe 'Thrift::Types::Known::Any' do
  describe 'encode' do
    let(:codec) { '' }

    shared_examples 'idempotent' do
      it 'should be idempotent' do
        Thrift::Types::Known::Any.from_object(obj, codec).to_object.should == obj
      end
    end

    subject { Thrift::Types::Known::Any.from_object(obj, codec) }

    context 'thrift struct' do
      let(:obj) { Thrift::Types::Value.from_object("foo") }

      it { subject.type.should == 'thrift/types.value.Value' }
      it { subject.value.should == '{"2":{"str":"foo"}}' }

      include_examples 'idempotent'

      context 'yaml only' do
        let(:codec) { 'yaml' }

        it { subject.type.should == 'thrift-yaml/types.value.Value' }
        it { subject.value.should == "string_value: foo\n" }

        include_examples 'idempotent'
      end

      context 'json only' do
        let(:codec) { 'json' }

        it { subject.type.should == 'thrift-json/types.value.Value' }
        it { subject.value.should == '{"string_value":"foo"}' }

        include_examples 'idempotent'
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
upfluence-thrift-2.6.8 spec/types/known/any_spec.rb
upfluence-thrift-2.6.1 spec/types/known/any_spec.rb
upfluence-thrift-2.4.4 spec/types/known/any_spec.rb
upfluence-thrift-2.3.1 spec/types/known/any_spec.rb
upfluence-thrift-2.3.0 spec/types/known/any_spec.rb