uvrb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/.gitignore +17 -0
  2. data/.gitmodules +3 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +13 -0
  5. data/Formula/libuv.rb +20 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +24 -0
  8. data/README.rdoc +70 -0
  9. data/Rakefile +29 -0
  10. data/examples/example +0 -0
  11. data/examples/example.c +37 -0
  12. data/examples/example.rb +29 -0
  13. data/examples/example_oop.rb +26 -0
  14. data/examples/python.py +1 -0
  15. data/examples/ruby.rb +1 -0
  16. data/examples/tcp_client_oop.rb +31 -0
  17. data/examples/tcp_example +0 -0
  18. data/examples/tcp_example.c +68 -0
  19. data/examples/tcp_example.rb +41 -0
  20. data/examples/tcp_example_oop.rb +43 -0
  21. data/examples/tcp_example_plain.rb +19 -0
  22. data/examples/tty_example.rb +20 -0
  23. data/features/async.feature +38 -0
  24. data/features/idle.feature +44 -0
  25. data/features/pipe.feature +150 -0
  26. data/features/prepare_and_check.feature +49 -0
  27. data/features/step_definitions/additional_cli_steps.rb +20 -0
  28. data/features/support/env.rb +6 -0
  29. data/lib/uv.rb +248 -0
  30. data/lib/uv/assertions.rb +24 -0
  31. data/lib/uv/async.rb +24 -0
  32. data/lib/uv/check.rb +27 -0
  33. data/lib/uv/error.rb +58 -0
  34. data/lib/uv/file.rb +221 -0
  35. data/lib/uv/file/stat.rb +35 -0
  36. data/lib/uv/filesystem.rb +335 -0
  37. data/lib/uv/fs_event.rb +21 -0
  38. data/lib/uv/handle.rb +65 -0
  39. data/lib/uv/idle.rb +27 -0
  40. data/lib/uv/listener.rb +26 -0
  41. data/lib/uv/loop.rb +326 -0
  42. data/lib/uv/net.rb +31 -0
  43. data/lib/uv/pipe.rb +47 -0
  44. data/lib/uv/prepare.rb +27 -0
  45. data/lib/uv/resource.rb +20 -0
  46. data/lib/uv/stream.rb +105 -0
  47. data/lib/uv/tasks.rb +27 -0
  48. data/lib/uv/tasks/mac.rb +23 -0
  49. data/lib/uv/tasks/unix.rb +23 -0
  50. data/lib/uv/tasks/win.rb +2 -0
  51. data/lib/uv/tcp.rb +162 -0
  52. data/lib/uv/timer.rb +48 -0
  53. data/lib/uv/tty.rb +30 -0
  54. data/lib/uv/types.rb +249 -0
  55. data/lib/uv/types/darwin_x64.rb +10 -0
  56. data/lib/uv/types/linux.rb +6 -0
  57. data/lib/uv/types/unix.rb +12 -0
  58. data/lib/uv/types/windows.rb +13 -0
  59. data/lib/uv/udp.rb +215 -0
  60. data/lib/uv/version.rb +3 -0
  61. data/lib/uvrb.rb +1 -0
  62. data/spec/shared_examples/handle.rb +54 -0
  63. data/spec/shared_examples/stream.rb +109 -0
  64. data/spec/spec_helper.rb +26 -0
  65. data/spec/uv/async_spec.rb +18 -0
  66. data/spec/uv/check_spec.rb +30 -0
  67. data/spec/uv/file_spec.rb +177 -0
  68. data/spec/uv/filesystem_spec.rb +246 -0
  69. data/spec/uv/fs_event_spec.rb +10 -0
  70. data/spec/uv/idle_spec.rb +30 -0
  71. data/spec/uv/loop_spec.rb +241 -0
  72. data/spec/uv/pipe_spec.rb +54 -0
  73. data/spec/uv/prepare_spec.rb +30 -0
  74. data/spec/uv/tcp_spec.rb +134 -0
  75. data/spec/uv/timer_spec.rb +61 -0
  76. data/spec/uv/tty_spec.rb +53 -0
  77. data/spec/uv/udp_spec.rb +190 -0
  78. data/uvrb.gemspec +28 -0
  79. metadata +247 -0
data/lib/uv/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module UV
2
+ VERSION = '0.1.0'
3
+ end
data/lib/uvrb.rb ADDED
@@ -0,0 +1 @@
1
+ require 'uv'
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for 'a handle' do
4
+ describe "#ref" do
5
+ it "calls UV.ref" do
6
+ UV.should_receive(:ref).with(pointer)
7
+
8
+ subject.ref
9
+ end
10
+ end
11
+
12
+ describe "#unref" do
13
+ it "calls UV.unref" do
14
+ UV.should_receive(:unref).with(pointer)
15
+
16
+ subject.unref
17
+ end
18
+ end
19
+
20
+ describe "#close" do
21
+ it "requires a block" do
22
+ expect { subject.close }.to raise_error(ArgumentError)
23
+ end
24
+
25
+ it "calls UV.close" do
26
+ UV.should_receive(:close).once.with(pointer, subject.method(:on_close))
27
+ subject.close {}
28
+ end
29
+ end
30
+
31
+ describe "#active?" do
32
+ it "is true for positive integers" do
33
+ UV.should_receive(:is_active).with(pointer).and_return(2)
34
+ subject.active?.should be_true
35
+ end
36
+
37
+ it "is false for integers less than 1" do
38
+ UV.should_receive(:is_active).with(pointer).and_return(0)
39
+ subject.active?.should be_false
40
+ end
41
+ end
42
+
43
+ describe "#closing?" do
44
+ it "is true for positive integers" do
45
+ UV.should_receive(:is_closing).with(pointer).and_return(1)
46
+ subject.closing?.should be_true
47
+ end
48
+
49
+ it "is false for integers less than 1" do
50
+ UV.should_receive(:is_closing).with(pointer).and_return(-1)
51
+ subject.closing?.should be_false
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for 'a stream' do
4
+ describe "#listen" do
5
+ it "raises if no block given" do
6
+ expect { subject.listen(128) }.to raise_error(ArgumentError)
7
+ end
8
+
9
+ it "calls UV.listen" do
10
+ backlog = 128
11
+ UV.should_receive(:listen).once.with(pointer, backlog, subject.method(:on_listen))
12
+ subject.listen(backlog) { |e| }
13
+ end
14
+ end
15
+
16
+ describe "#accept" do
17
+ let(:client_pointer) { double() }
18
+ let(:client) { double() }
19
+
20
+ before(:each) do
21
+ client.stub(:handle) { client_pointer }
22
+ end
23
+
24
+ it "makes another stream and calls UV.accept with current and other pointers" do
25
+ loop.should_receive(handle_name).once.and_return(client)
26
+ UV.should_receive(:accept).with(pointer, client_pointer)
27
+ subject.accept.should == client
28
+ end
29
+ end
30
+
31
+ describe "#start_read" do
32
+ it "raises if no block given" do
33
+ expect { subject.start_read }.to raise_error(ArgumentError)
34
+ end
35
+
36
+ it "calls UV.read_start" do
37
+ UV.should_receive(:read_start).with(pointer, subject.method(:on_allocate), subject.method(:on_read))
38
+ subject.start_read { |e, data| }
39
+ end
40
+ end
41
+
42
+ describe "#stop_read" do
43
+ it "calls UV.read_stop" do
44
+ UV.should_receive(:read_stop).with(pointer)
45
+ subject.stop_read
46
+ end
47
+ end
48
+
49
+ describe "#write" do
50
+ let(:write_request) { double() }
51
+ let(:buffer) { double() }
52
+ let(:buffer_pointer) { double() }
53
+
54
+ it "raises if no block given" do
55
+ expect { subject.write("123") }.to raise_error(ArgumentError)
56
+ end
57
+
58
+ it "calls UV.write" do
59
+ data = "some random string"
60
+ size = data.size
61
+
62
+ FFI::MemoryPointer.should_receive(:from_string).with(data).and_return(buffer_pointer)
63
+ UV.should_receive(:buf_init).with(buffer_pointer, size).and_return(buffer)
64
+ UV.should_receive(:create_request).with(:uv_write).and_return(write_request)
65
+ UV.should_receive(:write).with(write_request, pointer, buffer, 1, subject.method(:on_write))
66
+
67
+ subject.write(data) { |e| }
68
+ end
69
+ end
70
+
71
+ describe "#shutdown" do
72
+ let(:shutdown_request) { double() }
73
+
74
+ it "raises if no block given" do
75
+ expect { subject.shutdown }.to raise_error(ArgumentError)
76
+ end
77
+
78
+ it "calls UV.shutdown" do
79
+ UV.should_receive(:create_request).with(:uv_shutdown).and_return(shutdown_request)
80
+ UV.should_receive(:shutdown).with(shutdown_request, pointer, subject.method(:on_shutdown))
81
+
82
+ subject.shutdown { |e| }
83
+ end
84
+ end
85
+
86
+ describe "#readable?" do
87
+ it "is true for positive integers" do
88
+ UV.should_receive(:is_readable).with(pointer).and_return(1)
89
+ subject.readable?.should be_true
90
+ end
91
+
92
+ it "is false for integers less than 1" do
93
+ UV.should_receive(:is_readable).with(pointer).and_return(-1)
94
+ subject.readable?.should be_false
95
+ end
96
+ end
97
+
98
+ describe "#writable?" do
99
+ it "is true for positive integers" do
100
+ UV.should_receive(:is_writable).with(pointer).and_return(1)
101
+ subject.writable?.should be_true
102
+ end
103
+
104
+ it "is false for integers less than 1" do
105
+ UV.should_receive(:is_writable).with(pointer).and_return(-1)
106
+ subject.writable?.should be_false
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,26 @@
1
+ require 'uvrb'
2
+
3
+ module UVHelper
4
+ def new_tcp
5
+ default_loop.tcp
6
+ end
7
+
8
+ def default_loop
9
+ UV::Loop.default
10
+ end
11
+
12
+ def run_loop
13
+ default_loop.run
14
+ end
15
+
16
+ def run_loop_once
17
+ default_loop.run_once
18
+ end
19
+ end
20
+
21
+ RSpec.configure do |c|
22
+ c.include UVHelper
23
+ end
24
+
25
+ require_relative 'shared_examples/handle'
26
+ require_relative 'shared_examples/stream'
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe UV::Async do
4
+ let(:handle_name) { :async }
5
+ let(:loop) { double() }
6
+ let(:pointer) { double() }
7
+ subject { UV::Async.new(loop, pointer) { |e| } }
8
+
9
+ it_behaves_like 'a handle'
10
+
11
+ describe "#call" do
12
+ it "calls UV.async_send" do
13
+ UV.should_receive(:async_send).with(pointer)
14
+
15
+ subject.call
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe UV::Check do
4
+ let(:handle_name) { :check }
5
+ let(:loop) { double() }
6
+ let(:pointer) { double() }
7
+ subject { UV::Check.new(loop, pointer) }
8
+
9
+ it_behaves_like 'a handle'
10
+
11
+ describe "#start" do
12
+ it "requires a block" do
13
+ expect { subject.start }.to raise_error(ArgumentError)
14
+ end
15
+
16
+ it "calls UV.check_start" do
17
+ UV.should_receive(:check_start).with(pointer, subject.method(:on_check))
18
+
19
+ subject.start { |e| }
20
+ end
21
+ end
22
+
23
+ describe "#stop" do
24
+ it "calls UV.check_stop" do
25
+ UV.should_receive(:check_stop).with(pointer)
26
+
27
+ subject.stop
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,177 @@
1
+ require 'spec_helper'
2
+
3
+ describe UV::File do
4
+ let(:loop) { double() }
5
+ let(:loop_pointer) { double() }
6
+ let(:fd) { rand(6555) }
7
+ subject { UV::File.new(loop, fd) }
8
+
9
+ before(:each) do
10
+ loop.stub(:to_ptr) { loop_pointer }
11
+ end
12
+
13
+ describe "#close" do
14
+ let(:close_request) { double() }
15
+
16
+ it "requires a block" do
17
+ expect { subject.close }.to raise_error(ArgumentError)
18
+ end
19
+
20
+ it "calls UV.fs_close" do
21
+ UV.should_receive(:create_request).with(:uv_fs).and_return(close_request)
22
+ UV.should_receive(:fs_close).with(loop_pointer, close_request, fd, subject.method(:on_close))
23
+
24
+ subject.close { |e| }
25
+ end
26
+ end
27
+
28
+ describe "#read" do
29
+ let(:read_request) { double() }
30
+ let(:length) { 1024 }
31
+ let(:read_buffer) { double() }
32
+ let(:offset) { 0 }
33
+
34
+ it "requires a block" do
35
+ expect { subject.read(length, offset) }.to raise_error(ArgumentError)
36
+ end
37
+
38
+ it "calls UV.fs_read" do
39
+ FFI::MemoryPointer.should_receive(:new).with(length).and_return(read_buffer)
40
+ UV.should_receive(:create_request).with(:uv_fs).and_return(read_request)
41
+ UV.should_receive(:fs_read).with(loop_pointer, read_request, fd, read_buffer, length, offset, subject.method(:on_read))
42
+
43
+ subject.read(length, offset) { |e, data| }
44
+ end
45
+ end
46
+
47
+ describe "#write" do
48
+ let(:offset) { 0 }
49
+ let(:data) { "some payload" }
50
+ let(:write_buffer_length) { data.size }
51
+ let(:write_buffer) { double() }
52
+ let(:write_request) { double() }
53
+
54
+ it "requires a block" do
55
+ expect { subject.write(data, offset) }.to raise_error(ArgumentError)
56
+ end
57
+
58
+ it "calls UV.fs_write" do
59
+ FFI::MemoryPointer.should_receive(:from_string).with(data).and_return(write_buffer)
60
+ UV.should_receive(:create_request).with(:uv_fs).and_return(write_request)
61
+ UV.should_receive(:fs_write).with(loop_pointer, write_request, fd, write_buffer, write_buffer_length, offset, subject.method(:on_write))
62
+
63
+ subject.write(data, offset) { |e| }
64
+ end
65
+ end
66
+
67
+ describe "#stat" do
68
+ let(:stat_request) { double() }
69
+
70
+ it "requires a block" do
71
+ expect { subject.stat }.to raise_error(ArgumentError)
72
+ end
73
+
74
+ it "calls UV.fs_fstat" do
75
+ UV.should_receive(:create_request).with(:uv_fs).and_return(stat_request)
76
+ UV.should_receive(:fs_fstat).with(loop_pointer, stat_request, fd, subject.method(:on_stat))
77
+
78
+ subject.stat { |e, stat| }
79
+ end
80
+ end
81
+
82
+ describe "#sync" do
83
+ let(:sync_request) { double() }
84
+
85
+ it "requires a block" do
86
+ expect { subject.sync }.to raise_error(ArgumentError)
87
+ end
88
+
89
+ it "calls UV.fs_fsync" do
90
+ UV.should_receive(:create_request).with(:uv_fs).and_return(sync_request)
91
+ UV.should_receive(:fs_fsync).with(loop_pointer, sync_request, fd, subject.method(:on_sync))
92
+
93
+ subject.sync { |e| }
94
+ end
95
+ end
96
+
97
+ describe "#datasync" do
98
+ let(:datasync_request) { double() }
99
+
100
+ it "requires a block" do
101
+ expect { subject.datasync }.to raise_error(ArgumentError)
102
+ end
103
+
104
+ it "calls UV.fs_fdatasync" do
105
+ UV.should_receive(:create_request).with(:uv_fs).and_return(datasync_request)
106
+ UV.should_receive(:fs_fdatasync).with(loop_pointer, datasync_request, fd, subject.method(:on_datasync))
107
+
108
+ subject.datasync { |e| }
109
+ end
110
+ end
111
+
112
+ describe "#truncate" do
113
+ let(:offset) { 0 }
114
+ let(:truncate_request) { double() }
115
+
116
+ it "requires a block" do
117
+ expect { subject.truncate(offset) }.to raise_error(ArgumentError)
118
+ end
119
+
120
+ it "calls UV.fs_ftruncate" do
121
+ UV.should_receive(:create_request).with(:uv_fs).and_return(truncate_request)
122
+ UV.should_receive(:fs_ftruncate).with(loop_pointer, truncate_request, fd, offset, subject.method(:on_truncate))
123
+
124
+ subject.truncate(offset) { |e| }
125
+ end
126
+ end
127
+
128
+ describe "#utime" do
129
+ let(:atime) { 1291404900 } # 2010-12-03 20:35:00
130
+ let(:mtime) { 400497753 } # 1982-09-10 11:22:33
131
+ let(:utime_request) { double() }
132
+
133
+ it "requires a block" do
134
+ expect { subject.utime(atime, mtime) }.to raise_error(ArgumentError)
135
+ end
136
+
137
+ it "calls UV.fs_futime" do
138
+ UV.should_receive(:create_request).with(:uv_fs).and_return(utime_request)
139
+ UV.should_receive(:fs_futime).with(loop_pointer, utime_request, fd, atime, mtime, subject.method(:on_utime))
140
+
141
+ subject.utime(atime, mtime) { |e| }
142
+ end
143
+ end
144
+
145
+ describe "#chmod" do
146
+ let(:mode) { 0755 }
147
+ let(:chmod_request) { double() }
148
+
149
+ it "requires a block" do
150
+ expect { subject.chmod(mode) }.to raise_error(ArgumentError)
151
+ end
152
+
153
+ it "calls UV.fs_fchmod" do
154
+ UV.should_receive(:create_request).with(:uv_fs).and_return(chmod_request)
155
+ UV.should_receive(:fs_fchmod).with(loop_pointer, chmod_request, fd, mode, subject.method(:on_chmod))
156
+
157
+ subject.chmod(mode) { |e| }
158
+ end
159
+ end
160
+
161
+ describe "#chown" do
162
+ let(:uid) { 0 }
163
+ let(:gid) { 0 }
164
+ let(:chown_request) { double() }
165
+
166
+ it "requires a block" do
167
+ expect { subject.chown(uid, gid) }.to raise_error(ArgumentError)
168
+ end
169
+
170
+ it "calls UV.fs_fchown" do
171
+ UV.should_receive(:create_request).with(:uv_fs).and_return(chown_request)
172
+ UV.should_receive(:fs_fchown).with(loop_pointer, chown_request, fd, uid, gid, subject.method(:on_chown))
173
+
174
+ subject.chown(uid, gid) { |e| }
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,246 @@
1
+ require 'spec_helper'
2
+
3
+ describe UV::Filesystem do
4
+ let(:loop) { double() }
5
+ let(:loop_pointer) { double() }
6
+ subject { UV::Filesystem.new(loop) }
7
+
8
+ before(:each) do
9
+ loop.stub(:to_ptr) { loop_pointer }
10
+ end
11
+
12
+ describe "#open" do
13
+ let(:path) { "/tmp/file" }
14
+ let(:mode) { 0755 }
15
+ let(:flags) { File::CREAT | File::EXCL | File::APPEND }
16
+ let(:open_request) { double() }
17
+
18
+ it "requires a block" do
19
+ expect { subject.open(path, flags, mode) }.to raise_error(ArgumentError)
20
+ end
21
+
22
+ it "calls UV.fs_open" do
23
+ UV.should_receive(:create_request).with(:uv_fs).and_return(open_request)
24
+ UV.should_receive(:fs_open).with(loop_pointer, open_request, path, flags, mode, subject.method(:on_open))
25
+
26
+ subject.open(path, flags, mode) { |e, file| }
27
+ end
28
+ end
29
+
30
+ describe "#unlink" do
31
+ let(:path) { "/tmp/file" }
32
+ let(:unlink_request) { double() }
33
+
34
+ it "requires a block" do
35
+ expect { subject.unlink(path) }.to raise_error(ArgumentError)
36
+ end
37
+
38
+ it "calls UV.fs_unlink" do
39
+ UV.should_receive(:create_request).with(:uv_fs).and_return(unlink_request)
40
+ UV.should_receive(:fs_unlink).with(loop_pointer, unlink_request, path, subject.method(:on_unlink))
41
+
42
+ subject.unlink(path) { |e| }
43
+ end
44
+ end
45
+
46
+ describe "#mkdir" do
47
+ let(:path) { "/tmp/dir" }
48
+ let(:mode) { 0777 }
49
+ let(:mkdir_request) { double() }
50
+
51
+ it "requires a block" do
52
+ expect { subject.mkdir(path) }.to raise_error(ArgumentError)
53
+ end
54
+
55
+ it "calls UV.fs_mkdir" do
56
+ UV.should_receive(:create_request).with(:uv_fs).and_return(mkdir_request)
57
+ UV.should_receive(:fs_mkdir).with(loop_pointer, mkdir_request, path, mode, subject.method(:on_mkdir))
58
+
59
+ subject.mkdir(path, mode) { |e| }
60
+ end
61
+ end
62
+
63
+ describe "#rmdir" do
64
+ let(:path) { "/tmp/dir" }
65
+ let(:rmdir_request) { double() }
66
+
67
+ it "requires a block" do
68
+ expect { subject.rmdir(path) }.to raise_error(ArgumentError)
69
+ end
70
+
71
+ it "calls UV.fs_rmdir" do
72
+ UV.should_receive(:create_request).with(:uv_fs).and_return(rmdir_request)
73
+ UV.should_receive(:fs_rmdir).with(loop_pointer, rmdir_request, path, subject.method(:on_rmdir))
74
+
75
+ subject.rmdir(path) { |e| }
76
+ end
77
+ end
78
+
79
+ describe "#readdir" do
80
+ let(:path) { '/tmp' }
81
+ let(:readdir_request) { double() }
82
+
83
+ it "requires a block" do
84
+ expect { subject.readdir(path) }.to raise_error(ArgumentError)
85
+ end
86
+
87
+ it "calls UV.fs_readdir" do
88
+ UV.should_receive(:create_request).with(:uv_fs).and_return(readdir_request)
89
+ UV.should_receive(:fs_readdir).with(loop_pointer, readdir_request, path, 0, subject.method(:on_readdir))
90
+
91
+ subject.readdir(path) { |e, files| }
92
+ end
93
+ end
94
+
95
+ describe "#stat" do
96
+ let(:path) { '/tmp/filename' }
97
+ let(:stat_request) { double() }
98
+
99
+ it "requires a block" do
100
+ expect { subject.stat(path) }.to raise_error(ArgumentError)
101
+ end
102
+
103
+ it "calls UV.fs_stat" do
104
+ UV.should_receive(:create_request).with(:uv_fs).and_return(stat_request)
105
+ UV.should_receive(:fs_stat).with(loop_pointer, stat_request, path, subject.method(:on_stat))
106
+
107
+ subject.stat(path) { |e, stat| }
108
+ end
109
+ end
110
+
111
+ describe "#rename" do
112
+ let(:old_path) { '/tmp/old_file' }
113
+ let(:new_path) { '/tmp/new_file' }
114
+ let(:rename_request) { double() }
115
+
116
+ it "requires a block" do
117
+ expect { subject.rename(old_path, new_path) }.to raise_error(ArgumentError)
118
+ end
119
+
120
+ it "calls UV.fs_rename" do
121
+ UV.should_receive(:create_request).with(:uv_fs).and_return(rename_request)
122
+ UV.should_receive(:fs_rename).with(loop_pointer, rename_request, old_path, new_path, subject.method(:on_rename))
123
+
124
+ subject.rename(old_path, new_path) { |e| }
125
+ end
126
+ end
127
+
128
+ describe "#chmod" do
129
+ let(:path) { '/tmp/somepath' }
130
+ let(:mode) { 0755 }
131
+ let(:chmod_request) { double() }
132
+
133
+ it "requires a block" do
134
+ expect { subject.chmod(path, mode) }.to raise_error(ArgumentError)
135
+ end
136
+
137
+ it "calls UV.fs_chmod" do
138
+ UV.should_receive(:create_request).with(:uv_fs).and_return(chmod_request)
139
+ UV.should_receive(:fs_chmod).with(loop_pointer, chmod_request, path, mode, subject.method(:on_chmod))
140
+
141
+ subject.chmod(path, mode) { |e| }
142
+ end
143
+ end
144
+
145
+ describe "#utime" do
146
+ let(:path) { '/tmp/filename' }
147
+ let(:atime) { 1291404900 } # 2010-12-03 20:35:00
148
+ let(:mtime) { 400497753 } # 1982-09-10 11:22:33
149
+ let(:utime_request) { double() }
150
+
151
+ it "requires a block" do
152
+ expect { subject.utime(path, atime, mtime) }.to raise_error(ArgumentError)
153
+ end
154
+
155
+ it "calls UV.fs_utime" do
156
+ UV.should_receive(:create_request).with(:uv_fs).and_return(utime_request)
157
+ UV.should_receive(:fs_utime).with(loop_pointer, utime_request, path, atime, mtime, subject.method(:on_utime))
158
+
159
+ subject.utime(path, atime, mtime) { |e| }
160
+ end
161
+ end
162
+
163
+ describe "#lstat" do
164
+ let(:path) { '/tmp/filename' }
165
+ let(:lstat_request) { double() }
166
+
167
+ it "requires a block" do
168
+ expect { subject.lstat(path) }.to raise_error(ArgumentError)
169
+ end
170
+
171
+ it "calls UV.fs_lstat" do
172
+ UV.should_receive(:create_request).with(:uv_fs).and_return(lstat_request)
173
+ UV.should_receive(:fs_lstat).with(loop_pointer, lstat_request, path, subject.method(:on_lstat))
174
+
175
+ subject.lstat(path) { |e, stat| }
176
+ end
177
+ end
178
+
179
+ describe "#link" do
180
+ let(:old_path) { '/tmp/old_file' }
181
+ let(:new_path) { '/tmp/new_file' }
182
+ let(:link_request) { double() }
183
+
184
+ it "requires a block" do
185
+ expect { subject.link(old_path, new_path) }.to raise_error(ArgumentError)
186
+ end
187
+
188
+ it "calls UV.fs_link" do
189
+ UV.should_receive(:create_request).with(:uv_fs).and_return(link_request)
190
+ UV.should_receive(:fs_link).with(loop_pointer, link_request, old_path, new_path, subject.method(:on_link))
191
+
192
+ subject.link(old_path, new_path) { |e| }
193
+ end
194
+ end
195
+
196
+ describe "#symlink" do
197
+ let(:old_path) { '/tmp/old_file' }
198
+ let(:new_path) { '/tmp/new_file' }
199
+ let(:symlink_request) { double() }
200
+
201
+ it "requires a block" do
202
+ expect { subject.symlink(old_path, new_path) }.to raise_error(ArgumentError)
203
+ end
204
+
205
+ it "calls UV.fs_link" do
206
+ UV.should_receive(:create_request).with(:uv_fs).and_return(symlink_request)
207
+ UV.should_receive(:fs_symlink).with(loop_pointer, symlink_request, old_path, new_path, 0, subject.method(:on_symlink))
208
+
209
+ subject.symlink(old_path, new_path) { |e| }
210
+ end
211
+ end
212
+
213
+ describe "#readlink" do
214
+ let(:path) { '/tmp/symlink' }
215
+ let(:readlink_request) { double() }
216
+
217
+ it "requires a block" do
218
+ expect { subject.readlink(path) }.to raise_error(ArgumentError)
219
+ end
220
+
221
+ it "calls UV.fs_readlink" do
222
+ UV.should_receive(:create_request).with(:uv_fs).and_return(readlink_request)
223
+ UV.should_receive(:fs_readlink).with(loop_pointer, readlink_request, path, subject.method(:on_readlink))
224
+
225
+ subject.readlink(path) { |e, path| }
226
+ end
227
+ end
228
+
229
+ describe "#chown" do
230
+ let(:path) { '/tmp/chownable_file' }
231
+ let(:uid) { 0 }
232
+ let(:gid) { 0 }
233
+ let(:chown_request) { double() }
234
+
235
+ it "requires a block" do
236
+ expect { subject.chown(path, uid, gid) }.to raise_error(ArgumentError)
237
+ end
238
+
239
+ it "calls UV.fs_chown" do
240
+ UV.should_receive(:create_request).with(:uv_fs).and_return(chown_request)
241
+ UV.should_receive(:fs_chown).with(loop_pointer, chown_request, path, uid, gid, subject.method(:on_chown))
242
+
243
+ subject.chown(path, uid, gid) { |e| }
244
+ end
245
+ end
246
+ end