summaryrefslogtreecommitdiff
path: root/spec/ruby/library/stringio/readline_spec.rb
blob: 085360707f8634a6c561959a88026d9720a6ca46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require_relative '../../spec_helper'
require "stringio"
require_relative 'fixtures/classes'
require_relative "shared/gets"

describe "StringIO#readline" do
  describe "when passed [separator]" do
    it_behaves_like :stringio_gets_separator, :readline

    it "raises an IOError if self is at the end" do
      @io = StringIO.new("this>is>an>example")

      @io.pos = 36
      -> { @io.readline(">") }.should raise_error(IOError)
    end
  end

  describe "when passed [limit]" do
    it_behaves_like :stringio_gets_limit, :readline

    it "raises an IOError if self is at the end" do
      @io = StringIO.new("this>is>an>example")

      @io.pos = 36
      -> { @io.readline(3) }.should raise_error(IOError)
    end
  end

  describe "when passed [separator] and [limit]" do
    it_behaves_like :stringio_gets_separator_and_limit, :readline

    it "raises an IOError if self is at the end" do
      @io = StringIO.new("this>is>an>example")

      @io.pos = 36
      -> { @io.readline(">", 3) }.should raise_error(IOError)
    end
  end

  describe "when passed no argument" do
    it_behaves_like :stringio_gets_no_argument, :readline

    it "raises an IOError if self is at the end" do
      @io = StringIO.new("this>is>an>example")

      @io.pos = 36
      -> { @io.readline }.should raise_error(IOError)
    end
  end

  describe "when passed [chomp]" do
    it_behaves_like :stringio_gets_chomp, :readline
  end

  describe "when in write-only mode" do
    it_behaves_like :stringio_gets_write_only, :readline
  end
end