Sha256: 44cfc7a911a7e615564145d799966a1a23922f6a2673ded6f5ae1624c951eaf0

Contents?: true

Size: 1.54 KB

Versions: 10

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper'

module BerkeleyLibrary
  module TIND
    module API
      describe Format do
        describe :to_s do
          it 'returns the value' do
            expected = { Format::ID => 'id', Format::XML => 'xml', Format::FILES => 'files', Format::JSON => 'json' }
            expected.each do |fmt, val|
              expect(fmt.value).to eq(val)
              expect(fmt.to_s).to eq(val)
            end
          end
        end

        describe :to_str do
          it 'returns the value' do
            { Format::ID => 'id', Format::XML => 'xml', Format::FILES => 'files' }.each do |fmt, val|
              expect(fmt.value).to eq(val)
              expect(fmt.to_str).to eq(val)
            end
          end
        end

        describe :ensure_format do
          it 'returns nil for nil' do
            expect(Format.ensure_format(nil)).to be_nil
          end

          it 'returns a Format' do
            expect(Format.ensure_format(Format::XML)).to be(Format::XML)
          end

          it 'accepts a string' do
            expect(Format.ensure_format('xml')).to be(Format::XML)
          end

          it 'accepts a symbol' do
            expect(Format.ensure_format(:xml)).to be(Format::XML)
          end

          it 'rejects unsupported values' do
            expect { Format.ensure_format('CORBA') }.to raise_error(ArgumentError)
          end

          it 'rejects inconvertible values' do
            expect { Format.ensure_format(Object.new) }.to raise_error(ArgumentError)
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
berkeley_library-tind-0.7.2 spec/berkeley_library/tind/api/format_spec.rb
berkeley_library-tind-0.7.1 spec/berkeley_library/tind/api/format_spec.rb
berkeley_library-tind-0.7.0 spec/berkeley_library/tind/api/format_spec.rb
berkeley_library-tind-0.6.0 spec/berkeley_library/tind/api/format_spec.rb
berkeley_library-tind-0.5.1 spec/berkeley_library/tind/api/format_spec.rb
berkeley_library-tind-0.5.0 spec/berkeley_library/tind/api/format_spec.rb
berkeley_library-tind-0.4.3 spec/berkeley_library/tind/api/format_spec.rb
berkeley_library-tind-0.4.2 spec/berkeley_library/tind/api/format_spec.rb
berkeley_library-tind-0.4.1 spec/berkeley_library/tind/api/format_spec.rb
berkeley_library-tind-0.4.0 spec/berkeley_library/tind/api/format_spec.rb