Sha256: ec4a10650a85ebecf0d1bac07ae1a5e2e8938251eda50acec6923ba2a0c4e938

Contents?: true

Size: 1.25 KB

Versions: 11

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper'

describe Monolens, 'object.keys' do
  context 'with string keys' do
    subject do
      Monolens.lens('object.keys' => ['str.upcase'])
    end

    it 'works as expected' do
      input = {
        'firstname' => 'Bernard',
        'lastname' => 'Lambeau'
      }
      expected = {
        'FIRSTNAME' => 'Bernard',
        'LASTNAME' => 'Lambeau'
      }
      expect(subject.call(input)).to eql(expected)
    end
  end

  context 'with symbol keys' do
    subject do
      Monolens.lens('object.keys' => ['coerce.string', 'str.upcase'])
    end

    it 'works as expected with Symbol keys' do
      input = {
        firstname: 'Bernard',
        lastname: 'Lambeau'
      }
      expected = {
        FIRSTNAME: 'Bernard',
        LASTNAME: 'Lambeau'
      }
      expect(subject.call(input)).to eql(expected)
    end
  end

  describe 'error handling' do
    let(:lens) do
      Monolens.lens('object.keys' => ['str.upcase'])
    end

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

    let(:input) do
      {
        'firstname' => 'Bernard',
        nil => 'Lambeau'
      }
    end

    it 'correctly updates the location' do
      expect(subject.location).to eql([nil])
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
monolens-0.6.4 spec/monolens/stdlib/object/test_keys.rb
monolens-0.6.3 spec/monolens/stdlib/object/test_keys.rb
monolens-0.6.2 spec/monolens/stdlib/object/test_keys.rb
monolens-0.6.1 spec/monolens/stdlib/object/test_keys.rb
monolens-0.6.0 spec/monolens/stdlib/object/test_keys.rb
monolens-0.5.3 spec/monolens/object/test_keys.rb
monolens-0.5.2 spec/monolens/object/test_keys.rb
monolens-0.5.1 spec/monolens/object/test_keys.rb
monolens-0.5.0 spec/monolens/object/test_keys.rb
monolens-0.4.0 spec/monolens/object/test_keys.rb
monolens-0.3.0 spec/monolens/object/test_keys.rb