Sha256: 858efaefd7208d797ae79fd095ace6de02c1d7665e0944d3d32b8403f81955f6

Contents?: true

Size: 807 Bytes

Versions: 10

Compression:

Stored size: 807 Bytes

Contents

require 'spec_helper'

describe Monolens, 'coerce.integer' do
  subject do
    Monolens.lens('coerce.integer')
  end

  it 'is idempotent' do
    expect(subject.call(12)).to eql(12)
  end

  it 'coerces valid integers' do
    expect(subject.call('12')).to eql(12)
  end

  describe 'error handling' do
    let(:lens) do
      Monolens.lens({
        'array.map' => {
          :lenses => 'coerce.integer'
        }
      })
    end

    subject do
      begin
        lens.call(input)
        nil
      rescue Monolens::LensError => ex
        ex
      end
    end

    let(:input) do
      ['12sh']
    end

    it 'fails on invalid integers' do
      expect(subject).to be_a(Monolens::LensError)
    end

    it 'properly sets the location' do
      expect(subject.location).to eql([0])
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
monolens-0.6.4 spec/monolens/stdlib/coerce/test_integer.rb
monolens-0.6.3 spec/monolens/stdlib/coerce/test_integer.rb
monolens-0.6.2 spec/monolens/stdlib/coerce/test_integer.rb
monolens-0.6.1 spec/monolens/stdlib/coerce/test_integer.rb
monolens-0.6.0 spec/monolens/stdlib/coerce/test_integer.rb
monolens-0.5.3 spec/monolens/coerce/test_integer.rb
monolens-0.5.2 spec/monolens/coerce/test_integer.rb
monolens-0.5.1 spec/monolens/coerce/test_integer.rb
monolens-0.5.0 spec/monolens/coerce/test_integer.rb
monolens-0.4.0 spec/monolens/coerce/test_integer.rb