Sha256: b5664fd833170e212db2df261f49665b4908dccef6a90ce15714951d4b251892

Contents?: true

Size: 973 Bytes

Versions: 12

Compression:

Stored size: 973 Bytes

Contents

require 'spec_helper'

describe Monolens, 'str.split' do
  context 'without options' do
    subject do
      Monolens.lens('str.split')
    end

    it 'splits a string as an array using space separator' do
      input = 'foo bar'
      expected = ['foo', 'bar']
      expect(subject.call(input)).to eql(expected)
    end

    it 'is greedy on spaces and splits on carriage returns and tabs' do
      input = "foo   bar\nbaz\tboz"
      expected = ['foo', 'bar', 'baz', 'boz']
      expect(subject.call(input)).to eql(expected)
    end
  end

  context 'when specifying the separator' do
    subject do
      Monolens.lens('str.split' => { separator: ',' })
    end

    it 'uses it' do
      input = 'foo,bar'
      expected = ['foo', 'bar']
      expect(subject.call(input)).to eql(expected)
    end

    it 'does not make whitespace magic' do
      input = "foo, bar"
      expected = ['foo', ' bar']
      expect(subject.call(input)).to eql(expected)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

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