io-like 0.3.1 → 0.4.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -1
  3. data/NEWS.md +14 -1
  4. data/README.md +75 -94
  5. data/lib/io/like.rb +1916 -1314
  6. data/lib/io/like_helpers/abstract_io.rb +512 -0
  7. data/lib/io/like_helpers/blocking_io.rb +86 -0
  8. data/lib/io/like_helpers/buffered_io.rb +555 -0
  9. data/lib/io/like_helpers/character_io/basic_reader.rb +122 -0
  10. data/lib/io/like_helpers/character_io/converter_reader.rb +252 -0
  11. data/lib/io/like_helpers/character_io.rb +529 -0
  12. data/lib/io/like_helpers/delegated_io.rb +250 -0
  13. data/lib/io/like_helpers/duplexed_io.rb +259 -0
  14. data/lib/io/like_helpers/io.rb +21 -0
  15. data/lib/io/like_helpers/io_wrapper.rb +290 -0
  16. data/lib/io/like_helpers/pipeline.rb +77 -0
  17. data/lib/io/like_helpers/ruby_facts.rb +33 -0
  18. data/lib/io/like_helpers.rb +14 -0
  19. metadata +107 -224
  20. data/.yardopts +0 -1
  21. data/Rakefile +0 -228
  22. data/ruby.1.8.mspec +0 -7
  23. data/spec/binmode_spec.rb +0 -29
  24. data/spec/close_read_spec.rb +0 -64
  25. data/spec/close_spec.rb +0 -36
  26. data/spec/close_write_spec.rb +0 -61
  27. data/spec/closed_spec.rb +0 -16
  28. data/spec/each_byte_spec.rb +0 -38
  29. data/spec/each_line_spec.rb +0 -11
  30. data/spec/each_spec.rb +0 -11
  31. data/spec/eof_spec.rb +0 -11
  32. data/spec/fixtures/classes.rb +0 -96
  33. data/spec/fixtures/gets.txt +0 -9
  34. data/spec/fixtures/numbered_lines.txt +0 -5
  35. data/spec/fixtures/one_byte.txt +0 -1
  36. data/spec/fixtures/paragraphs.txt +0 -7
  37. data/spec/fixtures/readlines.txt +0 -6
  38. data/spec/flush_spec.rb +0 -8
  39. data/spec/getc_spec.rb +0 -44
  40. data/spec/gets_spec.rb +0 -212
  41. data/spec/isatty_spec.rb +0 -6
  42. data/spec/lineno_spec.rb +0 -84
  43. data/spec/output_spec.rb +0 -47
  44. data/spec/pos_spec.rb +0 -53
  45. data/spec/print_spec.rb +0 -97
  46. data/spec/printf_spec.rb +0 -24
  47. data/spec/putc_spec.rb +0 -57
  48. data/spec/puts_spec.rb +0 -99
  49. data/spec/read_spec.rb +0 -162
  50. data/spec/readchar_spec.rb +0 -49
  51. data/spec/readline_spec.rb +0 -60
  52. data/spec/readlines_spec.rb +0 -140
  53. data/spec/readpartial_spec.rb +0 -92
  54. data/spec/rewind_spec.rb +0 -56
  55. data/spec/seek_spec.rb +0 -72
  56. data/spec/shared/each.rb +0 -204
  57. data/spec/shared/eof.rb +0 -116
  58. data/spec/shared/pos.rb +0 -39
  59. data/spec/shared/tty.rb +0 -12
  60. data/spec/shared/write.rb +0 -53
  61. data/spec/sync_spec.rb +0 -56
  62. data/spec/sysread_spec.rb +0 -87
  63. data/spec/sysseek_spec.rb +0 -68
  64. data/spec/syswrite_spec.rb +0 -60
  65. data/spec/tell_spec.rb +0 -7
  66. data/spec/to_io_spec.rb +0 -19
  67. data/spec/tty_spec.rb +0 -6
  68. data/spec/ungetc_spec.rb +0 -118
  69. data/spec/write_spec.rb +0 -61
  70. data/spec_helper.rb +0 -49
  71. /data/{LICENSE-rubyspec → rubyspec/LICENSE} +0 -0
@@ -1,60 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require File.dirname(__FILE__) + '/fixtures/classes'
3
-
4
- describe "IO::Like#readline" do
5
- before :each do
6
- testfile = File.dirname(__FILE__) + '/fixtures/gets.txt'
7
- @contents = File.read(testfile)
8
- @io = File.open(testfile, 'r')
9
- @iowrapper = IOWrapper.open(@io)
10
- end
11
-
12
- after :each do
13
- @iowrapper.close unless @iowrapper.closed?
14
- @io.close unless @io.closed?
15
- end
16
-
17
- it "returns the next line on the stream" do
18
- @iowrapper.readline.should == "Voici la ligne une.\n"
19
- @iowrapper.readline.should == "Qui è la linea due.\n"
20
- end
21
-
22
- it "goes back to first position after a rewind" do
23
- @iowrapper.readline.should == "Voici la ligne une.\n"
24
- @iowrapper.rewind
25
- @iowrapper.readline.should == "Voici la ligne une.\n"
26
- end
27
-
28
- it "is modified by the cursor position" do
29
- @iowrapper.seek(1)
30
- @iowrapper.readline.should == "oici la ligne une.\n"
31
- end
32
-
33
- it "reads and returns all data available before a SystemCallError is raised when the separator is nil" do
34
- # Overrride @io.sysread to raise SystemCallError every other time it's
35
- # called.
36
- class << @io
37
- alias :sysread_orig :sysread
38
- def sysread(length)
39
- if @error_raised then
40
- @error_raised = false
41
- sysread_orig(length)
42
- else
43
- @error_raised = true
44
- raise SystemCallError, 'Test Error'
45
- end
46
- end
47
- end
48
-
49
- lambda { @iowrapper.readline(nil) }.should raise_error(SystemCallError)
50
- @iowrapper.readline(nil).should == @contents
51
- end
52
-
53
- it "raises EOFError on end of stream" do
54
- lambda { loop { @iowrapper.readline } }.should raise_error(EOFError)
55
- end
56
-
57
- it "raises IOError on closed stream" do
58
- lambda { IOSpecs.closed_file.readline }.should raise_error(IOError)
59
- end
60
- end
@@ -1,140 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require File.dirname(__FILE__) + '/fixtures/classes'
3
-
4
- describe "IO::Like#readlines when passed no arguments" do
5
- before(:each) do
6
- @io = File.open(File.dirname(__FILE__) + '/fixtures/readlines.txt')
7
- @iowrapper = IOWrapper.open(@io)
8
- end
9
-
10
- after(:each) do
11
- @iowrapper.close
12
- @io.close
13
- end
14
-
15
- it "returns an Array containing lines based on $/" do
16
- begin
17
- old_sep, $/ = $/, " "
18
- @iowrapper.readlines.should == [
19
- "Voici ", "la ", "ligne ", "une.\nQui ", "\303\250 ", "la ", "linea ",
20
- "due.\nAqu\303\255 ", "est\303\241 ", "la ", "l\303\255nea ",
21
- "tres.\nIst ", "hier ", "Linie ", "vier.\nEst\303\241 ", "aqui ", "a ",
22
- "linha ", "cinco.\nHere ", "is ", "line ", "six.\n"
23
- ]
24
- ensure
25
- $/ = old_sep
26
- end
27
- end
28
-
29
- it "updates self's position" do
30
- @iowrapper.readlines
31
- @iowrapper.pos.should eql(134)
32
- end
33
-
34
- it "updates self's lineno based on the number of lines read" do
35
- @iowrapper.readlines
36
- @iowrapper.lineno.should eql(6)
37
- end
38
-
39
- it "does not change $_" do
40
- $_ = "test"
41
- @iowrapper.readlines(">")
42
- $_.should == "test"
43
- end
44
-
45
- it "returns an empty Array when self is at the end" do
46
- @iowrapper.pos = 134
47
- @iowrapper.readlines.should == []
48
- end
49
- end
50
-
51
- describe "IO::Like#readlines when passed [separator]" do
52
- before(:each) do
53
- @io = File.open(File.dirname(__FILE__) + '/fixtures/readlines.txt')
54
- @iowrapper = IOWrapper.open(@io)
55
- end
56
-
57
- after(:each) do
58
- @iowrapper.close
59
- @io.close
60
- end
61
-
62
- it "returns an Array containing lines based on the passed separator" do
63
- @iowrapper.readlines('r').should == [
64
- "Voici la ligne une.\nQui \303\250 la linea due.\nAqu\303\255 est\303\241 la l\303\255nea tr",
65
- "es.\nIst hier",
66
- " Linie vier",
67
- ".\nEst\303\241 aqui a linha cinco.\nHer",
68
- "e is line six.\n"
69
- ]
70
- end
71
-
72
- it "returns an empty Array when self is at the end" do
73
- @iowrapper.pos = 134
74
- @iowrapper.readlines('r').should == []
75
- end
76
-
77
- it "updates self's lineno based on the number of lines read" do
78
- @iowrapper.readlines('r')
79
- @iowrapper.lineno.should eql(5)
80
- end
81
-
82
- it "updates self's position based on the number of characters read" do
83
- @iowrapper.readlines("r")
84
- @iowrapper.pos.should eql(134)
85
- end
86
-
87
- it "does not change $_" do
88
- $_ = "test"
89
- @iowrapper.readlines("r")
90
- $_.should == "test"
91
- end
92
-
93
- it "returns an Array containing all paragraphs when the passed separator is an empty String" do
94
- IOWrapper.open(File.open(File.dirname(__FILE__) + '/fixtures/paragraphs.txt')) do |io|
95
- io.readlines("").should == [
96
- "This is\n\n",
97
- "an example\n\n",
98
- "of paragraphs."
99
- ]
100
- end
101
- end
102
-
103
- it "returns the remaining content as one line starting at the current position when passed nil" do
104
- @iowrapper.pos = 5
105
- @iowrapper.readlines(nil).should == [
106
- " la ligne une.\nQui \303\250 la linea due.\n" +
107
- "Aqu\303\255 est\303\241 la l\303\255nea tres.\n" +
108
- "Ist hier Linie vier.\nEst\303\241 aqui a linha cinco.\n" +
109
- "Here is line six.\n"
110
- ]
111
- end
112
-
113
- it "tries to convert the passed separator to a String using #to_str" do
114
- obj = mock('to_str')
115
- obj.stub!(:to_str).and_return("r")
116
- @iowrapper.readlines(obj).should == [
117
- "Voici la ligne une.\nQui \303\250 la linea due.\nAqu\303\255 est\303\241 la l\303\255nea tr",
118
- "es.\nIst hier",
119
- " Linie vier",
120
- ".\nEst\303\241 aqui a linha cinco.\nHer",
121
- "e is line six.\n"]
122
- end
123
- end
124
-
125
- describe "IO::Like#readlines when in write-only mode" do
126
- it "raises an IOError" do
127
- path = tmp("write_only_specs")
128
- IOWrapper.open(File.open(path, 'a')) do |io|
129
- lambda { io.readlines }.should raise_error(IOError)
130
- end
131
-
132
- File.open(path) do |io|
133
- IOWrapper.open(io) do |iowrapper|
134
- io.close_read
135
- lambda { iowrapper.readlines }.should raise_error(IOError)
136
- end
137
- end
138
- File.unlink(path) if File.exists?(path)
139
- end
140
- end
@@ -1,92 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require File.dirname(__FILE__) + '/fixtures/classes'
3
-
4
- describe "IO::Like#readpartial" do
5
- before :each do
6
- @rd, @wr = IO.pipe
7
- @iowrapper_rd, @iowrapper_wr = IOWrapper.open(@rd), IOWrapper.open(@wr)
8
- @iowrapper_wr.sync = true
9
- end
10
-
11
- after :each do
12
- @iowrapper_rd.close unless @iowrapper_rd.closed?
13
- @iowrapper_wr.close unless @iowrapper_wr.closed?
14
- @rd.close unless @rd.closed?
15
- @wr.close unless @wr.closed?
16
- end
17
-
18
- it "raises IOError on closed stream" do
19
- lambda { IOSpecs.closed_file.readpartial(10) }.should raise_error(IOError)
20
-
21
- @iowrapper_rd.close
22
- lambda { @iowrapper_rd.readpartial(10) }.should raise_error(IOError)
23
- end
24
-
25
- it "reads at most the specified number of bytes" do
26
- @iowrapper_wr.write("foobar")
27
-
28
- # buffered read
29
- @iowrapper_rd.read(1).should == 'f'
30
- # return only specified number, not the whole buffer
31
- @iowrapper_rd.readpartial(1).should == "o"
32
- end
33
-
34
- it "reads after ungetc with data in the buffer" do
35
- @iowrapper_wr.write("foobar")
36
- c = @iowrapper_rd.getc
37
- @iowrapper_rd.ungetc(c)
38
- @iowrapper_rd.readpartial(3).should == "foo"
39
- @iowrapper_rd.readpartial(3).should == "bar"
40
- end
41
-
42
- it "reads after ungetc without data in the buffer" do
43
- @iowrapper_wr.write("f")
44
- c = @iowrapper_rd.getc
45
- @iowrapper_rd.ungetc(c)
46
- @iowrapper_rd.readpartial(2).should == "f"
47
-
48
- # now, also check that the ungot char is cleared and
49
- # not returned again
50
- @iowrapper_wr.write("b")
51
- @iowrapper_rd.readpartial(2).should == "b"
52
- end
53
-
54
- it "discards the existing buffer content upon successful read" do
55
- buffer = "existing"
56
- @iowrapper_wr.write("hello world")
57
- @iowrapper_wr.close
58
- @wr.close
59
- @iowrapper_rd.readpartial(11, buffer)
60
- buffer.should == "hello world"
61
- end
62
-
63
- it "raises EOFError on EOF" do
64
- @iowrapper_wr.write("abc")
65
- @iowrapper_wr.close
66
- @wr.close
67
- @iowrapper_rd.readpartial(10).should == 'abc'
68
- lambda { @iowrapper_rd.readpartial(10) }.should raise_error(EOFError)
69
- end
70
-
71
- it "discards the existing buffer content upon error" do
72
- buffer = 'hello'
73
- @iowrapper_wr.close
74
- @wr.close
75
- lambda { @iowrapper_rd.readpartial(1, buffer) }.should raise_error(EOFError)
76
- buffer.should be_empty
77
- end
78
-
79
- it "raises IOError if the stream is closed" do
80
- @iowrapper_wr.close
81
- @wr.close
82
- lambda { @iowrapper_rd.readpartial(1) }.should raise_error(IOError)
83
- end
84
-
85
- it "raises ArgumentError if the negative argument is provided" do
86
- lambda { @iowrapper_rd.readpartial(-1) }.should raise_error(ArgumentError)
87
- end
88
-
89
- it "immediately returns an empty string if the length argument is 0" do
90
- @iowrapper_rd.readpartial(0).should == ""
91
- end
92
- end
data/spec/rewind_spec.rb DELETED
@@ -1,56 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require File.dirname(__FILE__) + '/fixtures/classes'
3
-
4
- describe "IO::Like#rewind" do
5
- before :each do
6
- @file = File.open(File.dirname(__FILE__) + '/fixtures/readlines.txt', 'r')
7
- @iowrapper = ReadableIOWrapper.open(@file)
8
- end
9
-
10
- after :each do
11
- @iowrapper.close unless @iowrapper.closed?
12
- @file.close unless @file.closed?
13
- end
14
-
15
- it "should return 0" do
16
- @iowrapper.rewind.should == 0
17
- end
18
-
19
- it "positions the instance to the beginning of input" do
20
- @iowrapper.readline.should == "Voici la ligne une.\n"
21
- @iowrapper.readline.should == "Qui è la linea due.\n"
22
- @iowrapper.rewind
23
- @iowrapper.readline.should == "Voici la ligne une.\n"
24
- end
25
-
26
- it "positions the instance to the beginning of input and clears EOF" do
27
- value = @iowrapper.read
28
- @iowrapper.rewind
29
- @iowrapper.eof?.should == false
30
- value.should == @iowrapper.read
31
- end
32
-
33
- it "sets lineno to 0" do
34
- @iowrapper.readline.should == "Voici la ligne une.\n"
35
- @iowrapper.lineno.should == 1
36
- @iowrapper.rewind
37
- @iowrapper.lineno.should == 0
38
- end
39
-
40
- it "works on write-only streams" do
41
- file = tmp('IO_Like__rewind.test')
42
- File.open(file, 'w') do |f|
43
- WritableIOWrapper.open(f) do |io|
44
- io.write('test1')
45
- io.rewind.should == 0
46
- io.write('test2')
47
- end
48
- end
49
- File.read(file).should == 'test2'
50
- File.delete(file)
51
- end
52
-
53
- it "raises IOError on closed stream" do
54
- lambda { IOSpecs.closed_file.rewind }.should raise_error(IOError)
55
- end
56
- end
data/spec/seek_spec.rb DELETED
@@ -1,72 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require File.dirname(__FILE__) + '/fixtures/classes'
3
-
4
- describe "IO::Like#seek" do
5
- before :each do
6
- @file = File.open(File.dirname(__FILE__) + '/fixtures/readlines.txt', 'r')
7
- @iowrapper = IOWrapper.open(@file)
8
- end
9
-
10
- after :each do
11
- @iowrapper.close unless @iowrapper.closed?
12
- @file.close unless @file.closed?
13
- end
14
-
15
- it "moves the read position relative to the current position with SEEK_CUR" do
16
- lambda { @iowrapper.seek(-1) }.should raise_error(Errno::EINVAL)
17
- @iowrapper.seek(10, IO::SEEK_CUR)
18
- @iowrapper.readline.should == "igne une.\n"
19
- @iowrapper.seek(-5, IO::SEEK_CUR)
20
- @iowrapper.readline.should == "une.\n"
21
- end
22
-
23
- it "moves the read position relative to the start with SEEK_SET" do
24
- @iowrapper.seek(1)
25
- @iowrapper.pos.should == 1
26
- @iowrapper.rewind
27
- @iowrapper.seek(42, IO::SEEK_SET)
28
- @iowrapper.readline.should == "quí está la línea tres.\n"
29
- @iowrapper.seek(5, IO::SEEK_SET)
30
- @iowrapper.readline.should == " la ligne une.\n"
31
- end
32
-
33
- it "moves the read position relative to the end with SEEK_END" do
34
- @iowrapper.seek(0, IO::SEEK_END)
35
- @iowrapper.tell.should == 134
36
- @iowrapper.seek(-25, IO::SEEK_END)
37
- @iowrapper.readline.should == "cinco.\n"
38
- end
39
-
40
- it "can handle any numerical argument without breaking" do
41
- @iowrapper.seek(1.2).should == 0
42
- @iowrapper.seek(2**32).should == 0
43
- @iowrapper.seek(1.23423423432e12).should == 0
44
- @iowrapper.seek(0.00000000000000000000001).should == 0
45
- lambda { @iowrapper.seek(2**128) }.should raise_error(RangeError)
46
- end
47
-
48
- it "raises IOError on closed stream" do
49
- lambda { IOSpecs.closed_file.seek(0) }.should raise_error(IOError)
50
- end
51
-
52
- it "moves the read position and clears EOF with SEEK_SET" do
53
- value = @iowrapper.read
54
- @iowrapper.seek(0, IO::SEEK_SET)
55
- @iowrapper.eof?.should == false
56
- value.should == @iowrapper.read
57
- end
58
-
59
- it "moves the read position and clears EOF with SEEK_CUR" do
60
- value = @iowrapper.read
61
- @iowrapper.seek(-1, IO::SEEK_CUR)
62
- @iowrapper.eof?.should == false
63
- value[-1].should == @iowrapper.read[0]
64
- end
65
-
66
- it "moves the read position and clears EOF with SEEK_END" do
67
- value = @iowrapper.read
68
- @iowrapper.seek(-1, IO::SEEK_END)
69
- @iowrapper.eof?.should == false
70
- value[-1].should == @iowrapper.read[0]
71
- end
72
- end
data/spec/shared/each.rb DELETED
@@ -1,204 +0,0 @@
1
- require File.dirname(__FILE__) + '/../fixtures/classes'
2
-
3
- describe :io_like__each, :shared => true do
4
- before(:each) do
5
- @old_rs = $/
6
- @io = File.open(IOSpecs.gets_fixtures)
7
- @iowrapper = ReadableIOWrapper.open(@io)
8
- end
9
-
10
- after(:each) do
11
- @iowrapper.close
12
- @io.close
13
- $/ = @old_rs
14
- end
15
-
16
- it "returns self" do
17
- @iowrapper.send(@method) { |l| l }.should == @iowrapper
18
- end
19
-
20
- it "yields each line to the passed block" do
21
- seen = []
22
- @iowrapper.send(@method) { |s| seen << s }
23
- seen.should == [
24
- "Voici la ligne une.\n", "Qui \303\250 la linea due.\n", "\n", "\n",
25
- "Aqu\303\255 est\303\241 la l\303\255nea tres.\n",
26
- "Ist hier Linie vier.\n", "\n", "Est\303\241 aqui a linha cinco.\n",
27
- "Here is line six.\n"
28
- ]
29
- end
30
-
31
- it "yields each line starting from the current position" do
32
- seen = []
33
- @iowrapper.pos = 40
34
- @iowrapper.send(@method) { |s| seen << s }
35
- seen.should == [
36
- "\n", "\n", "\n", "Aqu\303\255 est\303\241 la l\303\255nea tres.\n",
37
- "Ist hier Linie vier.\n", "\n", "Est\303\241 aqui a linha cinco.\n",
38
- "Here is line six.\n"
39
- ]
40
- end
41
-
42
- it "does not change $_" do
43
- $_ = "test"
44
- @iowrapper.send(@method) { |s| s }
45
- $_.should == "test"
46
- end
47
-
48
- it "uses $/ as the default line separator" do
49
- seen = []
50
- $/ = " "
51
- @iowrapper.send(@method) { |s| seen << s }
52
- seen.should == [
53
- "Voici ", "la ", "ligne ", "une.\nQui ", "\303\250 ", "la ", "linea ",
54
- "due.\n\n\nAqu\303\255 ", "est\303\241 ", "la ", "l\303\255nea ",
55
- "tres.\nIst ", "hier ", "Linie ", "vier.\n\nEst\303\241 ", "aqui ",
56
- "a ", "linha ", "cinco.\nHere ", "is ", "line ", "six.\n"
57
- ]
58
- end
59
-
60
- it "raises IOError on write-only stream" do
61
- # method must have a block in order to raise the IOError.
62
- # MRI 1.8.7 returns enumerator if block is not provided.
63
- # See [ruby-core:16557].
64
- lambda do
65
- IOSpecs.writable_iowrapper do |iowrapper|
66
- iowrapper.send(@method) {}
67
- end
68
- end.should raise_error(IOError)
69
- end
70
-
71
- it "raises IOError on closed stream" do
72
- # method must have a block in order to raise the IOError.
73
- # MRI 1.8.7 returns enumerator if block is not provided.
74
- # See [ruby-core:16557].
75
- lambda { IOSpecs.closed_file.send(@method) {} }.should raise_error(IOError)
76
- end
77
-
78
- ruby_version_is "" ... "1.8.7" do
79
- it "yields a LocalJumpError when passed no block" do
80
- lambda { @iowrapper.send(@method) }.should raise_error(LocalJumpError)
81
- end
82
- end
83
-
84
- ruby_version_is "1.8.7" do
85
- it "returns an Enumerator when passed no block" do
86
- enum = @iowrapper.send(@method, " ")
87
- enum.instance_of?(Enumerable::Enumerator).should be_true
88
-
89
- enum.to_a.should == [
90
- "Voici la ligne une.\n", "Qui \303\250 la linea due.\n", "\n", "\n",
91
- "Aqu\303\255 est\303\241 la l\303\255nea tres.\n",
92
- "Ist hier Linie vier.\n", "\n", "Est\303\241 aqui a linha cinco.\n",
93
- "Here is line six.\n"
94
- ]
95
- end
96
- end
97
- end
98
-
99
- describe :io_like__each_separator, :shared => true do
100
- before(:each) do
101
- @io = File.open(IOSpecs.gets_fixtures)
102
- @iowrapper = ReadableIOWrapper.open(@io)
103
- end
104
-
105
- after(:each) do
106
- @iowrapper.close
107
- @io.close
108
- end
109
-
110
- it "returns self" do
111
- @iowrapper.send(@method, " ") { |l| l }.should equal(@iowrapper)
112
- end
113
-
114
- it "uses the passed argument as the line separator" do
115
- seen = []
116
- @iowrapper.send(@method, " ") { |s| seen << s }
117
- seen.should == [
118
- "Voici ", "la ", "ligne ", "une.\nQui ", "\303\250 ", "la ", "linea ",
119
- "due.\n\n\nAqu\303\255 ", "est\303\241 ", "la ", "l\303\255nea ",
120
- "tres.\nIst ", "hier ", "Linie ", "vier.\n\nEst\303\241 ", "aqui ", "a ",
121
- "linha ", "cinco.\nHere ", "is ", "line ", "six.\n"
122
- ]
123
- end
124
-
125
- it "does not change $_" do
126
- $_ = "test"
127
- @iowrapper.send(@method, " ") { |s| s }
128
- $_.should == "test"
129
- end
130
-
131
- it "tries to convert the passed separator to a String using #to_str" do
132
- obj = mock("to_str")
133
- obj.stub!(:to_str).and_return(" ")
134
-
135
- seen = []
136
- @iowrapper.send(@method, obj) { |l| seen << l }
137
- seen.should == [
138
- "Voici ", "la ", "ligne ", "une.\nQui ", "\303\250 ", "la ", "linea ",
139
- "due.\n\n\nAqu\303\255 ", "est\303\241 ", "la ", "l\303\255nea ",
140
- "tres.\nIst ", "hier ", "Linie ", "vier.\n\nEst\303\241 ", "aqui ", "a ",
141
- "linha ", "cinco.\nHere ", "is ", "line ", "six.\n"
142
- ]
143
- end
144
-
145
- it "yields self's content starting from the current position when the passed separator is nil" do
146
- seen = []
147
- @iowrapper.pos = 100
148
- @iowrapper.send(@method, nil) { |s| seen << s }
149
- seen.should == ["qui a linha cinco.\nHere is line six.\n"]
150
- end
151
-
152
- it "yields each paragraph when passed an empty String as separator" do
153
- seen = []
154
- para_file = File.dirname(__FILE__) + '/../fixtures/paragraphs.txt'
155
- File.open(para_file) do |io|
156
- ReadableIOWrapper.open(io) do |iowrapper|
157
- iowrapper.send(@method, "") { |s| seen << s }
158
- end
159
- end
160
- seen.should == ["This is\n\n", "an example\n\n", "of paragraphs."]
161
- end
162
-
163
- it "raises IOError on write-only stream" do
164
- # method must have a block in order to raise the IOError.
165
- # MRI 1.8.7 returns enumerator if block is not provided.
166
- # See [ruby-core:16557].
167
- lambda do
168
- IOSpecs.writable_iowrapper do |iowrapper|
169
- iowrapper.send(@method, " ") {}
170
- end
171
- end.should raise_error(IOError)
172
- end
173
-
174
- it "raises IOError on closed stream" do
175
- # method must have a block in order to raise the IOError.
176
- # MRI 1.8.7 returns enumerator if block is not provided.
177
- # See [ruby-core:16557].
178
- lambda do
179
- IOSpecs.closed_file.send(@method, " ") {}
180
- end.should raise_error(IOError)
181
- end
182
-
183
- ruby_version_is "" ... "1.8.7" do
184
- it "yields a LocalJumpError when passed no block" do
185
- lambda do
186
- @iowrapper.send(@method, " ")
187
- end.should raise_error(LocalJumpError)
188
- end
189
- end
190
-
191
- ruby_version_is "1.8.7" do
192
- it "returns an Enumerator when passed no block" do
193
- enum = @iowrapper.send(@method, " ")
194
- enum.instance_of?(Enumerable::Enumerator).should be_true
195
-
196
- enum.to_a.should == [
197
- "Voici ", "la ", "ligne ", "une.\nQui ", "\303\250 ", "la ", "linea ",
198
- "due.\n\n\nAqu\303\255 ", "est\303\241 ", "la ", "l\303\255nea ",
199
- "tres.\nIst ", "hier ", "Linie ", "vier.\n\nEst\303\241 ", "aqui ",
200
- "a ", "linha ", "cinco.\nHere ", "is ", "line ", "six.\n"
201
- ]
202
- end
203
- end
204
- end