Sha256: b0a6d471590e2c11b71d6479508deccad9aa5494f368d7468daeb747e4eafa35

Contents?: true

Size: 1.16 KB

Versions: 23

Compression:

Stored size: 1.16 KB

Contents

require 'spec_helper'

RSpec.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

23 entries across 23 versions & 3 rubygems

Version Path
protobuf-core-3.5.0 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.6.12 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.6.11 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.6.10 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.6.9 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.6.7 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.6.6 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.6.2 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.6.1 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.6.0 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.5.5 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.5.4 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.5.3 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.5.2 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.5.1 spec/lib/protobuf/field/float_field_spec.rb
prepor-protobuf-3.5.1 spec/lib/protobuf/field/float_field_spec.rb
prepor-protobuf-3.5.0 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.5.0 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.4.4 spec/lib/protobuf/field/float_field_spec.rb
protobuf-3.4.3 spec/lib/protobuf/field/float_field_spec.rb