summaryrefslogtreecommitdiff
path: root/spec/ruby/library/stringio/gets_spec.rb
blob: ac876f0b4f3521c720f24b2a8d9b0225d8d3df7a (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
59
60
61
require_relative '../../spec_helper'
require "stringio"
require_relative "shared/gets"

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

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

      @io.pos = 36
      @io.gets(">").should be_nil
      @io.gets(">").should be_nil
    end
  end

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

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

      @io.pos = 36
      @io.gets(3).should be_nil
      @io.gets(3).should be_nil
    end
  end

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

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

      @io.pos = 36
      @io.gets(">", 3).should be_nil
      @io.gets(">", 3).should be_nil
    end
  end

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

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

      @io.pos = 36
      @io.gets.should be_nil
      @io.gets.should be_nil
    end
  end

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

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