Sha256: 31c0c2eff0723d99147ee66bf959d34c31086f1923e7f0773800a5a0371d7c0f

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

require 'pr/fields/invalid_value'
require 'pr/fields/float_field'

describe 'a float field' do
  let(:klass)   { PR::Fields::FloatField }
  let(:value)   { double "value" }
  let(:options) { Hash.new }
  let(:field)   { klass.new value, options }

  describe "default value" do
    specify { expect(klass.new.raw).to eq '' }
    specify { expect(klass.new.options).to eq({}) }
  end

  describe '#options' do
    it 'has retrievable options' do
      expect(field.options).to eq options
    end
  end

  describe "#raw" do
    it 'returns the raw value' do
      expect(field.raw).to eq value
    end
  end

  describe "#populate" do
    let(:value) { 3.141 }
    let(:field) { klass.new }

    subject { field.populate value }

    specify { subject; expect(field.raw).to eq("3.141") }
  end

  describe "#convert" do

    context "where passed a stringified float value" do
      let(:value) { "3.4" }

      it "should return the float intepretation" do
        expect(field.convert).to eq(3.4)
      end
    end

    context "where passed a string not containing a float value" do
      let(:value) { "One Point Oh" }

      specify { expect { field.convert }.to raise_error PR::Fields::InvalidValue }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pr-1.0.0 spec/unit/pr/fields/float_field_spec.rb
pr-0.0.7 spec/unit/pr/fields/float_field_spec.rb