Sha256: d1f3ce89fd199e0d89744a87ea08dbd2c79cbb2950f7a8c5dae6d0d5d640dbbe

Contents?: true

Size: 1.16 KB

Versions: 11

Compression:

Stored size: 1.16 KB

Contents

require 'spec_helper'

describe Protobuf::Field::FloatField do

  class SomeFloatMessage < ::Protobuf::Message
    optional :float, :some_float, 1
  end

  let(:instance) { SomeFloatMessage.new }

  describe '#define_setter' do
    subject { instance.some_float = value; instance.some_float }

    context 'when set with an int' do
      let(:value) { 100 }

      it 'is readable as a float' do
        expect(subject).to eq(100.0)
      end
    end

    context 'when set with a float' do
      let(:value) { 100.1 }

      it 'is readable as a float' do
        expect(subject).to eq(100.1)
      end
    end

    context 'when set with a string of a float' do
      let(:value) { "101.1" }

      it 'is readable as a float' do
        expect(subject).to eq(101.1)
      end
    end

    context 'when set with a non-numeric string' do
      let(:value) { "aaaa" }

      it 'throws an error' do
        expect { subject }.to raise_error(ArgumentError)
      end
    end

    context 'when set with something that is not a float' do
      let(:value) { [ 1, 2, 3 ] }

      it 'throws an error' do
        expect { subject }.to raise_error(TypeError)
      end
    end
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
protobuf-3.3.6 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.3.5 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.3.4 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.3.3 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.3.2 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.3.1 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.3.0 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.2.1 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.2.0 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.1.0 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.0.5 spec/lib/protobuf/field/float_field_spec.rb