2018-03-04 15:09:32 +00:00
|
|
|
require_relative '../../spec_helper'
|
|
|
|
require_relative 'fixtures/classes'
|
|
|
|
require_relative 'shared/each_line'
|
|
|
|
require_relative 'shared/each_line_without_block'
|
2017-05-07 12:04:49 +00:00
|
|
|
|
|
|
|
describe "String#lines" do
|
2018-01-29 16:08:16 +00:00
|
|
|
it_behaves_like :string_each_line, :lines
|
2017-05-07 12:04:49 +00:00
|
|
|
|
|
|
|
it "returns an array when no block given" do
|
2018-10-27 10:48:40 +00:00
|
|
|
ary = "hello world".lines(' ')
|
2017-05-07 12:04:49 +00:00
|
|
|
ary.should == ["hello ", "world"]
|
|
|
|
end
|
2017-10-28 15:15:48 +00:00
|
|
|
|
2019-04-27 18:53:23 +02:00
|
|
|
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"]
|
2017-10-28 15:15:48 +00:00
|
|
|
end
|
|
|
|
end
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|