Sha256: db3091e253124e2be0fae013d88ef2d9aab8830d9e17676f7a988d5254cd42db

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

describe BikePOA::Helpers::ForceField do
  describe 'force integer' do

    class DummySubject < Hashie::Dash
      include BikePOA::Helpers::ForceField
      property :normal
      property :number

      force_integer :number
    end

    describe "when setting property directly" do
      let(:dummy) { DummySubject.new }

      it "accepts any value that is castable to integer" do
        expect { dummy.number = '42' }.to_not raise_error(ArgumentError)
        expect { dummy.number = 42   }.to_not raise_error(ArgumentError)
        expect { dummy.number = 42.0 }.to_not raise_error(ArgumentError)
      end
      it "raises when the value is not castable to integer" do
        expect { dummy.number = "abc" }.to raise_error(ArgumentError)
        expect { dummy.number = "a12" }.to raise_error(ArgumentError)
      end
      it 'lets you put anything into non-forced fields' do
        expect { DummySubject.new(normal: 'abc1123') }.to_not raise_error
      end
    end

    describe "when loading the Dash from a hash" do
      it 'accepts values castable to integer' do
        expect { DummySubject.new(number: '678') }.to_not raise_error(ArgumentError)
      end
      it "raises when one of the forced-fields is invalid" do
        expect { DummySubject.new(number: "abc") }.to raise_error(ArgumentError)
      end
      it 'lets you put anything into non-forced fields' do
        expect { DummySubject.new(normal: 'abc1123') }.to_not raise_error
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bikepoa-tools-0.3.0 spec/helpers_spec.rb