io-like 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.yardopts +1 -0
  2. data/LICENSE +22 -57
  3. data/{LICENSE.rubyspec → LICENSE-rubyspec} +0 -0
  4. data/{NEWS → NEWS.md} +10 -5
  5. data/README.md +269 -0
  6. data/Rakefile +228 -0
  7. data/ruby.1.8.mspec +7 -0
  8. data/spec/binmode_spec.rb +29 -0
  9. data/spec/close_read_spec.rb +64 -0
  10. data/spec/close_spec.rb +36 -0
  11. data/spec/close_write_spec.rb +61 -0
  12. data/spec/closed_spec.rb +16 -0
  13. data/spec/each_byte_spec.rb +38 -0
  14. data/spec/each_line_spec.rb +11 -0
  15. data/spec/each_spec.rb +11 -0
  16. data/spec/eof_spec.rb +11 -0
  17. data/spec/fixtures/classes.rb +96 -0
  18. data/spec/fixtures/gets.txt +9 -0
  19. data/spec/fixtures/numbered_lines.txt +5 -0
  20. data/spec/fixtures/one_byte.txt +1 -0
  21. data/spec/fixtures/paragraphs.txt +7 -0
  22. data/spec/fixtures/readlines.txt +6 -0
  23. data/spec/flush_spec.rb +8 -0
  24. data/spec/getc_spec.rb +44 -0
  25. data/spec/gets_spec.rb +212 -0
  26. data/spec/isatty_spec.rb +6 -0
  27. data/spec/lineno_spec.rb +84 -0
  28. data/spec/output_spec.rb +47 -0
  29. data/spec/pos_spec.rb +53 -0
  30. data/spec/print_spec.rb +97 -0
  31. data/spec/printf_spec.rb +24 -0
  32. data/spec/putc_spec.rb +57 -0
  33. data/spec/puts_spec.rb +99 -0
  34. data/spec/read_spec.rb +162 -0
  35. data/spec/readchar_spec.rb +49 -0
  36. data/spec/readline_spec.rb +60 -0
  37. data/spec/readlines_spec.rb +140 -0
  38. data/spec/readpartial_spec.rb +92 -0
  39. data/spec/rewind_spec.rb +56 -0
  40. data/spec/seek_spec.rb +72 -0
  41. data/spec/shared/each.rb +204 -0
  42. data/spec/shared/eof.rb +116 -0
  43. data/spec/shared/pos.rb +39 -0
  44. data/spec/shared/tty.rb +12 -0
  45. data/spec/shared/write.rb +53 -0
  46. data/spec/sync_spec.rb +56 -0
  47. data/spec/sysread_spec.rb +87 -0
  48. data/spec/sysseek_spec.rb +68 -0
  49. data/spec/syswrite_spec.rb +60 -0
  50. data/spec/tell_spec.rb +7 -0
  51. data/spec/to_io_spec.rb +19 -0
  52. data/spec/tty_spec.rb +6 -0
  53. data/spec/ungetc_spec.rb +118 -0
  54. data/spec/write_spec.rb +61 -0
  55. data/spec_helper.rb +49 -0
  56. metadata +223 -32
  57. data/CONTRIBUTORS +0 -15
  58. data/GPL +0 -676
  59. data/HACKING +0 -123
  60. data/LEGAL +0 -56
  61. data/MANIFEST +0 -10
  62. data/README +0 -150
@@ -0,0 +1,140 @@
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
@@ -0,0 +1,92 @@
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
@@ -0,0 +1,56 @@
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
@@ -0,0 +1,72 @@
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
@@ -0,0 +1,204 @@
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