2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
|
|
|
require_relative 'fixtures/classes'
|
|
|
|
require_relative 'shared/each_line'
|
|
|
|
require_relative 'shared/each_line_without_block'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "String#lines" do
|
2018-01-29 11:08:16 -05:00
|
|
|
it_behaves_like :string_each_line, :lines
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
it "returns an array when no block given" do
|
2018-10-27 06:48:40 -04:00
|
|
|
ary = "hello world".lines(' ')
|
2017-05-07 08:04:49 -04:00
|
|
|
ary.should == ["hello ", "world"]
|
|
|
|
end
|
2017-10-28 11:15:48 -04:00
|
|
|
|
|
|
|
ruby_version_is '2.4' do
|
|
|
|
context "when `chomp` keyword argument is passed" do
|
|
|
|
it "removes new line characters" do
|
|
|
|
"hello \nworld\n".lines(chomp: true).should == ["hello ", "world"]
|
|
|
|
"hello \r\nworld\r\n".lines(chomp: true).should == ["hello ", "world"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|