sys-filesystem 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,26 +1,8 @@
1
1
  require 'rake'
2
2
  require 'rake/clean'
3
- require 'rake/testtask'
3
+ require 'rspec/core/rake_task'
4
4
 
5
- CLEAN.include('**/*.gem', '**/*.rbc', '**/*.rbx')
6
-
7
- desc "Run the test suite"
8
- Rake::TestTask.new("test") do |t|
9
- if File::ALT_SEPARATOR
10
- t.libs << 'lib/windows'
11
- else
12
- t.libs << 'lib/unix'
13
- end
14
-
15
- t.warning = true
16
- t.verbose = true
17
- t.test_files = FileList['test/test_sys_filesystem.rb']
18
- end
19
-
20
- desc "Run the example program"
21
- task :example do |t|
22
- sh "ruby -Ilib -Ilib/unix -Ilib/windows examples/example_stat.rb"
23
- end
5
+ CLEAN.include('**/*.gem', '**/*.rbc', '**/*.rbx', '**/*.lock')
24
6
 
25
7
  namespace :gem do
26
8
  desc "Build the sys-filesystem gem"
@@ -28,7 +10,7 @@ namespace :gem do
28
10
  require 'rubygems/package'
29
11
  spec = eval(IO.read('sys-filesystem.gemspec'))
30
12
  spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
31
- Gem::Package.build(spec, true)
13
+ Gem::Package.build(spec)
32
14
  end
33
15
 
34
16
  desc "Install the sys-filesystem gem"
@@ -38,4 +20,12 @@ namespace :gem do
38
20
  end
39
21
  end
40
22
 
41
- task :default => :test
23
+ desc "Run the example program"
24
+ task :example do |t|
25
+ sh "ruby -Ilib -Ilib/unix -Ilib/windows examples/example_stat.rb"
26
+ end
27
+
28
+ desc "Run the test suite"
29
+ RSpec::Core::RakeTask.new(:spec)
30
+
31
+ task :default => :spec
@@ -0,0 +1,72 @@
1
+ ######################################################################
2
+ # example_mount.rb
3
+ #
4
+ # Example program that demonstrates the Filesystem.mount method.
5
+ # Simulates the `mount` command in ruby
6
+ ######################################################################
7
+ require 'optparse'
8
+
9
+ options = {:mount_options => []}
10
+ OptionParser.new do |opts|
11
+ opts.banner = "Usage: #$0 [-o options] [-t external_type] special node"
12
+
13
+ opts.on("-o=OPTIONS", "Set one or many mount options (comma delimited)") do |opts|
14
+ options[:mount_options] += opts.split(',')
15
+ end
16
+
17
+ opts.on("-r", "Set readonly flag") do
18
+ options[:read_only] = true
19
+ end
20
+
21
+ opts.on("-t=EXTERNAL_TYPE", "Set the filesystem type") do |type|
22
+ options[:type] = type
23
+ end
24
+
25
+ opts.on("-v", "--version", "Display version") do
26
+ options[:version] = true
27
+ end
28
+
29
+ opts.separator ""
30
+ opts.separator "Examples:"
31
+ opts.separator ""
32
+ opts.separator " NFS: ruby #$0 -t nfs 192.168.0.10:/var/nfs /mnt/nfs"
33
+ opts.separator ""
34
+ opts.separator " SMB: ruby #$0 -t cifs //192.168.0.10/share /mnt/smb/ -o username=user,password=pass,domain=example.com"
35
+ opts.separator ""
36
+ end.parse!
37
+
38
+ require 'sys/filesystem'
39
+ include Sys
40
+
41
+ if options[:version]
42
+ puts "Sys::Filesystem::VERSION: #{Filesystem::VERSION}"
43
+ exit
44
+ end
45
+
46
+ def die msg
47
+ warn msg
48
+ exit 1
49
+ end
50
+
51
+ mount_flags = options[:read_only] ? Filesystem::MNT_RDONLY : 0
52
+ mnt_path, mnt_point = ARGV[0,2]
53
+
54
+ case options[:type]
55
+ when "cifs"
56
+ # keep mnt_path as is
57
+ when "nfs"
58
+ host, path, err = mnt_path.split(":")
59
+
60
+ die "ERROR: mount_pount '#{mnt_path}' should only contain 1 ':'" if err
61
+
62
+ mnt_path = ":#{path}"
63
+ options[:mount_options] << "addr=#{host}"
64
+ else
65
+ die "ERROR: unknown mount type!"
66
+ end
67
+
68
+ Filesystem.mount mnt_path,
69
+ mnt_point,
70
+ options[:type],
71
+ mount_flags,
72
+ options[:mount_options].join(',')
@@ -1,7 +1,7 @@
1
1
  module Sys
2
2
  class Filesystem
3
3
  # The version of the sys-filesystem library
4
- VERSION = '1.3.0'.freeze
4
+ VERSION = '1.4.0'.freeze
5
5
  end
6
6
  end
7
7
 
@@ -198,7 +198,27 @@ module Sys
198
198
  # Returns a Sys::Filesystem::Stat object containing information about the
199
199
  # +path+ on the filesystem.
200
200
  #
201
+ # Examples:
202
+ #
203
+ # # path
204
+ # Sys::Filesystem.stat("path")
205
+ #
206
+ # # Pathname
207
+ # pathname = Pathname.new("path")
208
+ # Sys::Filesystem.stat(pathname)
209
+ #
210
+ # # File
211
+ # file = File.open("file", "r")
212
+ # Sys::Filesystem.stat(file)
213
+ #
214
+ # # Dir
215
+ # dir = Dir.open("/")
216
+ # Sys::Filesystem.stat(dir)
217
+ #
201
218
  def self.stat(path)
219
+ path = path.path if path.respond_to?(:path) # File, Dir
220
+ path = path.to_s if path.respond_to?(:to_s) # Pathname
221
+
202
222
  fs = Statvfs.new
203
223
 
204
224
  if statvfs(path, fs) < 0
@@ -7,7 +7,7 @@ module Sys
7
7
 
8
8
  ffi_lib FFI::Library::LIBC
9
9
 
10
- if RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
10
+ if RbConfig::CONFIG['host_os'] =~ /sunos|solaris|linux/i
11
11
  attach_function(:statvfs, :statvfs64, [:string, :pointer], :int)
12
12
  else
13
13
  attach_function(:statvfs, [:string, :pointer], :int)
@@ -19,7 +19,7 @@ module Sys
19
19
  begin
20
20
  attach_function(:umount_c, :umount, [:string], :int)
21
21
  rescue FFI::NotFoundError
22
- if RbConfig::CONFIG['host_os'] =~ /darwin|osx|mach/i
22
+ if RbConfig::CONFIG['host_os'] =~ /darwin|osx|mach|bsd/i
23
23
  attach_function(:umount_c, :unmount, [:string], :int)
24
24
  end
25
25
  end
@@ -39,6 +39,21 @@ module Sys
39
39
  :f_mntfromname, [:char, MNAMELEN],
40
40
  :f_mntonname, [:char, MNAMELEN]
41
41
  )
42
+ elsif RbConfig::CONFIG['host_os'] =~ /linux/i
43
+ layout(
44
+ :f_type, :ulong,
45
+ :f_bsize, :ulong,
46
+ :f_blocks, :uint64,
47
+ :f_bfree, :uint64,
48
+ :f_bavail, :uint64,
49
+ :f_files, :uint64,
50
+ :f_ffree, :uint64,
51
+ :f_fsid, [:int, 2],
52
+ :f_namelen, :ulong,
53
+ :f_frsize, :ulong,
54
+ :f_flags, :ulong,
55
+ :f_spare, [:ulong, 4]
56
+ )
42
57
  else
43
58
  layout(
44
59
  :f_bsize, :uint32,
@@ -108,22 +123,35 @@ module Sys
108
123
  :f_fstr, [:char, 32],
109
124
  :f_filler, [:ulong, 16]
110
125
  )
126
+ elsif RbConfig::CONFIG['host'] =~ /i686/i
127
+ layout(
128
+ :f_bsize, :ulong,
129
+ :f_frsize, :ulong,
130
+ :f_blocks, :uint,
131
+ :f_bfree, :uint,
132
+ :f_bavail, :uint,
133
+ :f_files, :uint,
134
+ :f_ffree, :uint,
135
+ :f_favail, :uint,
136
+ :f_fsid, :ulong,
137
+ :f_flag, :ulong,
138
+ :f_namemax, :ulong,
139
+ :f_spare, [:int, 6]
140
+ )
111
141
  else
112
142
  layout(
113
143
  :f_bsize, :ulong,
114
144
  :f_frsize, :ulong,
115
- :f_blocks, :ulong,
116
- :f_bfree, :ulong,
117
- :f_bavail, :ulong,
118
- :f_files, :ulong,
119
- :f_ffree, :ulong,
120
- :f_favail, :ulong,
145
+ :f_blocks, :uint64,
146
+ :f_bfree, :uint64,
147
+ :f_bavail, :uint64,
148
+ :f_files, :uint64,
149
+ :f_ffree, :uint64,
150
+ :f_favail, :uint64,
121
151
  :f_fsid, :ulong,
122
152
  :f_flag, :ulong,
123
153
  :f_namemax, :ulong,
124
- :f_ftype, :ulong,
125
- :f_basetype, [:char, 16],
126
- :f_str, [:char, 16]
154
+ :f_spare, [:int, 6]
127
155
  )
128
156
  end
129
157
  end
@@ -259,10 +259,25 @@ module Sys
259
259
  #
260
260
  # Examples:
261
261
  #
262
+ # # Regular directory
262
263
  # Sys::Filesystem.stat("C:\\")
263
264
  # Sys::Filesystem.stat("C:\\Documents and Settings\\some_user")
264
265
  #
266
+ # # Pathname
267
+ # pathname = Pathname.new("C:\\")
268
+ # Sys::Filesystem.stat(pathname)
269
+ #
270
+ # # Dir
271
+ # dir = Dir.open("C:\\")
272
+ # Sys::Filesystem.stat(dir)
273
+ #
274
+ # Note that on Windows you cannot stat a regular file because
275
+ # Windows won't like it. It must be a directory in some form.
276
+ #
265
277
  def self.stat(path)
278
+ path = path.path if path.respond_to?(:path) # Dir
279
+ path = path.to_s if path.respond_to?(:to_s) # Pathname
280
+
266
281
  bytes_avail = FFI::MemoryPointer.new(:ulong_long)
267
282
  bytes_free = FFI::MemoryPointer.new(:ulong_long)
268
283
  total_bytes = FFI::MemoryPointer.new(:ulong_long)
@@ -270,7 +285,7 @@ module Sys
270
285
  mpoint = mount_point(path).to_s
271
286
  mpoint << '/' unless mpoint.end_with?('/')
272
287
 
273
- wpath = path.to_s.wincode
288
+ wpath = path.to_s.wincode
274
289
 
275
290
  # We need this call for the 64 bit support
276
291
  unless GetDiskFreeSpaceExW(wpath, bytes_avail, total_bytes, bytes_free)
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.filter_run_excluding(:windows) unless Gem.win_platform?
5
+ config.filter_run_excluding(:unix) if Gem.win_platform?
6
+ end
@@ -0,0 +1,389 @@
1
+ ####################################################################
2
+ # sys_filesystem_unix_spec.rb
3
+ #
4
+ # Specs for the Sys::Filesystem.stat method and related stuff.
5
+ # This test suite should be run via the 'rake spec' task.
6
+ ####################################################################
7
+ require 'spec_helper'
8
+ require 'sys-filesystem'
9
+ require 'pathname'
10
+
11
+ RSpec.describe Sys::Filesystem, :unix => true do
12
+ let(:solaris) { RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i }
13
+ let(:linux) { RbConfig::CONFIG['host_os'] =~ /linux/i }
14
+ let(:bsd) { RbConfig::CONFIG['host_os'] =~ /bsd/i }
15
+ let(:darwin) { RbConfig::CONFIG['host_os'] =~ /mac|darwin/i }
16
+ let(:root) { '/' }
17
+
18
+ before do
19
+ @stat = Sys::Filesystem.stat(root)
20
+ @size = 58720256
21
+ end
22
+
23
+ example "version number is set to the expected value" do
24
+ expect(Sys::Filesystem::VERSION).to eq('1.4.0')
25
+ expect(Sys::Filesystem::VERSION).to be_frozen
26
+ end
27
+
28
+ example "stat path works as expected" do
29
+ expect(@stat).to respond_to(:path)
30
+ expect(@stat.path).to eq(root)
31
+ end
32
+
33
+ example "stat block_size works as expected" do
34
+ expect(@stat).to respond_to(:block_size)
35
+ expect(@stat.block_size).to be_kind_of(Numeric)
36
+ end
37
+
38
+ example "stat fragment_size works as expected" do
39
+ expect(@stat).to respond_to(:fragment_size)
40
+ expect(@stat.fragment_size).to be_kind_of(Numeric)
41
+ end
42
+
43
+ example "stat fragment_size is a plausible value" do
44
+ expect(@stat.fragment_size).to be >= 512
45
+ expect(@stat.fragment_size).to be <= 16384
46
+ end
47
+
48
+ example "stat blocks works as expected" do
49
+ expect(@stat).to respond_to(:blocks)
50
+ expect(@stat.blocks).to be_kind_of(Numeric)
51
+ end
52
+
53
+ example "stat blocks_free works as expected" do
54
+ expect(@stat).to respond_to(:blocks_free)
55
+ expect(@stat.blocks_free).to be_kind_of(Numeric)
56
+ end
57
+
58
+ example "stat blocks_available works as expected" do
59
+ expect(@stat).to respond_to(:blocks_available)
60
+ expect(@stat.blocks_available).to be_kind_of(Numeric)
61
+ end
62
+
63
+ example "stat files works as expected" do
64
+ expect(@stat).to respond_to(:files)
65
+ expect(@stat.files).to be_kind_of(Numeric)
66
+ end
67
+
68
+ example "stat inodes is an alias for files" do
69
+ expect(@stat).to respond_to(:inodes)
70
+ expect(@stat.method(:inodes)).to eq(@stat.method(:files))
71
+ end
72
+
73
+ example "stat files tree works as expected" do
74
+ expect(@stat).to respond_to(:files_free)
75
+ expect(@stat.files_free).to be_kind_of(Numeric)
76
+ end
77
+
78
+ example "stat inodes_free is an alias for files_free" do
79
+ expect(@stat).to respond_to(:inodes_free)
80
+ expect(@stat.method(:inodes_free)).to eq(@stat.method(:files_free))
81
+ end
82
+
83
+ example "stat files_available works as expected" do
84
+ expect(@stat).to respond_to(:files_available)
85
+ expect(@stat.files_available).to be_kind_of(Numeric)
86
+ end
87
+
88
+ example "stat inodes_available is an alias for files_available" do
89
+ expect(@stat).to respond_to(:inodes_available)
90
+ expect(@stat.method(:inodes_available)).to eq(@stat.method(:files_available))
91
+ end
92
+
93
+ example "stat filesystem_id works as expected" do
94
+ expect(@stat).to respond_to(:filesystem_id)
95
+ expect(@stat.filesystem_id).to be_kind_of(Integer)
96
+ end
97
+
98
+ example "stat flags works as expected" do
99
+ expect(@stat).to respond_to(:flags)
100
+ expect(@stat.flags).to be_kind_of(Numeric)
101
+ end
102
+
103
+ example "stat name_max works as expected" do
104
+ expect(@stat).to respond_to(:name_max)
105
+ expect(@stat.name_max).to be_kind_of(Numeric)
106
+ end
107
+
108
+ example "stat base_type works as expected" do
109
+ skip "base_type test skipped except on Solaris" unless solaris
110
+
111
+ expect(@stat).to respond_to(:base_type)
112
+ expect(@stat.base_type).to be_kind_of(String)
113
+ end
114
+
115
+ example "stat constants are defined" do
116
+ expect(Sys::Filesystem::Stat::RDONLY).not_to be_nil
117
+ expect(Sys::Filesystem::Stat::NOSUID).not_to be_nil
118
+ end
119
+
120
+ example "stat constants for solaris are defined" do
121
+ skip "NOTRUNC test skipped except on Solaris" unless solaris
122
+ expect(Sys::Filesystem::Stat::NOTRUNC).not_to be_nil
123
+ end
124
+
125
+ example "stat bytes_total works as expected" do
126
+ expect(@stat).to respond_to(:bytes_total)
127
+ expect(@stat.bytes_total).to be_kind_of(Numeric)
128
+ end
129
+
130
+ example "stat bytes_free works as expected" do
131
+ expect(@stat).to respond_to(:bytes_free)
132
+ expect(@stat.bytes_free).to be_kind_of(Numeric)
133
+ expect(@stat.blocks_free * @stat.fragment_size).to eq(@stat.bytes_free)
134
+ end
135
+
136
+ example "stat bytes_available works as expected" do
137
+ expect(@stat).to respond_to(:bytes_available)
138
+ expect(@stat.bytes_available).to be_kind_of(Numeric)
139
+ expect(@stat.blocks_available * @stat.fragment_size).to eq(@stat.bytes_available)
140
+ end
141
+
142
+ example "stat bytes works as expected" do
143
+ expect(@stat).to respond_to(:bytes_used)
144
+ expect(@stat.bytes_used).to be_kind_of(Numeric)
145
+ end
146
+
147
+ example "stat percent_used works as expected" do
148
+ expect(@stat).to respond_to(:percent_used)
149
+ expect(@stat.percent_used).to be_kind_of(Float)
150
+ end
151
+
152
+ example "stat singleton method requires an argument" do
153
+ expect{ Sys::Filesystem.stat }.to raise_error(ArgumentError)
154
+ end
155
+
156
+ example "stat case_insensitive method works as expected" do
157
+ expected = darwin ? true : false
158
+ expect(@stat.case_insensitive?).to eq(expected)
159
+ expect(Sys::Filesystem.stat(Dir.home).case_insensitive?).to eq(expected)
160
+ end
161
+
162
+ example "stat case_sensitive method works as expected" do
163
+ expected = darwin ? false : true
164
+ expect(@stat.case_sensitive?).to eq(expected)
165
+ expect(Sys::Filesystem.stat(Dir.home).case_sensitive?).to eq(expected)
166
+ end
167
+
168
+ example "numeric helper methods are defined" do
169
+ expect(@size).to respond_to(:to_kb)
170
+ expect(@size).to respond_to(:to_mb)
171
+ expect(@size).to respond_to(:to_gb)
172
+ expect(@size).to respond_to(:to_tb)
173
+ end
174
+
175
+ example "to_kb works as expected" do
176
+ expect(@size.to_kb).to eq(57344)
177
+ end
178
+
179
+ example "to_mb works as expected" do
180
+ expect(@size.to_mb).to eq(56)
181
+ end
182
+
183
+ example "to_gb works as expected" do
184
+ expect(@size.to_gb).to eq(0)
185
+ end
186
+
187
+ context "Filesystem.stat(Pathname)" do
188
+ before do
189
+ @stat_pathname = Sys::Filesystem.stat(Pathname.new(root))
190
+ end
191
+
192
+ example "stat with Pathname argument works as expected" do
193
+ expect(@stat_pathname.class).to eq(@stat.class)
194
+ expect(@stat_pathname.path).to eq(@stat.path)
195
+ expect(@stat_pathname.block_size).to eq(@stat.block_size)
196
+ expect(@stat_pathname.fragment_size).to eq(@stat.fragment_size)
197
+ expect(@stat_pathname.blocks).to eq(@stat.blocks)
198
+ expect(@stat_pathname.blocks_free).to eq(@stat.blocks_free)
199
+ expect(@stat_pathname.blocks_available).to eq(@stat.blocks_available)
200
+ expect(@stat_pathname.files).to eq(@stat.files)
201
+ expect(@stat_pathname.files_free).to eq(@stat.files_free)
202
+ expect(@stat_pathname.files_available).to eq(@stat.files_available)
203
+ expect(@stat_pathname.filesystem_id).to eq(@stat.filesystem_id)
204
+ expect(@stat_pathname.flags).to eq(@stat.flags)
205
+ expect(@stat_pathname.name_max).to eq(@stat.name_max)
206
+ expect(@stat_pathname.base_type).to eq(@stat.base_type)
207
+ end
208
+ end
209
+
210
+ context "Filesystem.stat(File)" do
211
+ before do
212
+ @stat_file = File.open(root){ |file| Sys::Filesystem.stat(file) }
213
+ end
214
+
215
+ example "stat with File argument works as expected" do
216
+ expect(@stat_file.class).to eq(@stat.class)
217
+ expect(@stat_file.path).to eq(@stat.path)
218
+ expect(@stat_file.block_size).to eq(@stat.block_size)
219
+ expect(@stat_file.fragment_size).to eq(@stat.fragment_size)
220
+ expect(@stat_file.blocks).to eq(@stat.blocks)
221
+ expect(@stat_file.blocks_free).to eq(@stat.blocks_free)
222
+ expect(@stat_file.blocks_available).to eq(@stat.blocks_available)
223
+ expect(@stat_file.files).to eq(@stat.files)
224
+ expect(@stat_file.files_free).to eq(@stat.files_free)
225
+ expect(@stat_file.files_available).to eq(@stat.files_available)
226
+ expect(@stat_file.filesystem_id).to eq(@stat.filesystem_id)
227
+ expect(@stat_file.flags).to eq(@stat.flags)
228
+ expect(@stat_file.name_max).to eq(@stat.name_max)
229
+ expect(@stat_file.base_type).to eq(@stat.base_type)
230
+ end
231
+ end
232
+
233
+ context "Filesystem.stat(Dir)" do
234
+ before do
235
+ @stat_dir = Dir.open(root){ |dir| Sys::Filesystem.stat(dir) }
236
+ end
237
+
238
+ example "stat with Dir argument works as expected" do
239
+ expect(@stat_dir.class).to eq(@stat.class)
240
+ expect(@stat_dir.path).to eq(@stat.path)
241
+ expect(@stat_dir.block_size).to eq(@stat.block_size)
242
+ expect(@stat_dir.fragment_size).to eq(@stat.fragment_size)
243
+ expect(@stat_dir.blocks).to eq(@stat.blocks)
244
+ expect(@stat_dir.blocks_free).to eq(@stat.blocks_free)
245
+ expect(@stat_dir.blocks_available).to eq(@stat.blocks_available)
246
+ expect(@stat_dir.files).to eq(@stat.files)
247
+ expect(@stat_dir.files_free).to eq(@stat.files_free)
248
+ expect(@stat_dir.files_available).to eq(@stat.files_available)
249
+ expect(@stat_dir.filesystem_id).to eq(@stat.filesystem_id)
250
+ expect(@stat_dir.flags).to eq(@stat.flags)
251
+ expect(@stat_dir.name_max).to eq(@stat.name_max)
252
+ expect(@stat_dir.base_type).to eq(@stat.base_type)
253
+ end
254
+ end
255
+
256
+ context "Filesystem::Mount" do
257
+ let(:mount){ Sys::Filesystem.mounts[0] }
258
+
259
+ before do
260
+ @array = []
261
+ end
262
+
263
+ example "mounts singleton method works as expected without a block" do
264
+ expect{ @array = Sys::Filesystem.mounts }.not_to raise_error
265
+ expect(@array[0]).to be_kind_of(Sys::Filesystem::Mount)
266
+ end
267
+
268
+ example "mounts singleton method works as expected with a block" do
269
+ expect{ Sys::Filesystem.mounts{ |m| @array << m } }.not_to raise_error
270
+ expect(@array[0]).to be_kind_of(Sys::Filesystem::Mount)
271
+ end
272
+
273
+ example "calling the mounts singleton method a large number of times does not cause issues" do
274
+ expect{ 1000.times{ @array = Sys::Filesystem.mounts } }.not_to raise_error
275
+ end
276
+
277
+ example "mount name method works as expected" do
278
+ expect(mount).to respond_to(:name)
279
+ expect(mount.name).to be_kind_of(String)
280
+ end
281
+
282
+ example "mount fsname is an alias for name" do
283
+ expect(mount).to respond_to(:fsname)
284
+ expect(mount.method(:fsname)).to eq(mount.method(:name))
285
+ end
286
+
287
+ example "mount point method works as expected" do
288
+ expect(mount).to respond_to(:mount_point)
289
+ expect(mount.mount_point).to be_kind_of(String)
290
+ end
291
+
292
+ example "mount dir is an alias for mount_point" do
293
+ expect(mount).to respond_to(:dir)
294
+ expect(mount.method(:dir)).to eq(mount.method(:mount_point))
295
+ end
296
+
297
+ example "mount mount_type works as expected" do
298
+ expect(mount).to respond_to(:mount_type)
299
+ expect(mount.mount_type).to be_kind_of(String)
300
+ end
301
+
302
+ example "mount options works as expected" do
303
+ expect(mount).to respond_to(:options)
304
+ expect(mount.options).to be_kind_of(String)
305
+ end
306
+
307
+ example "mount opts is an alias for options" do
308
+ expect(mount).to respond_to(:opts)
309
+ expect(mount.method(:opts)).to eq(mount.method(:options))
310
+ end
311
+
312
+ example "mount time works as expected" do
313
+ expect(mount).to respond_to(:mount_time)
314
+
315
+ if solaris
316
+ expect(mount.mount_time).to be_kind_of(Time)
317
+ else
318
+ expect(mount.mount_time).to be_nil
319
+ end
320
+ end
321
+
322
+ example "mount dump_frequency works as expected" do
323
+ msg = 'dump_frequency test skipped on this platform'
324
+ skip msg if solaris || bsd || darwin
325
+ expect(mount).to respond_to(:dump_frequency)
326
+ expect(mount.dump_frequency).to be_kind_of(Numeric)
327
+ end
328
+
329
+ example "mount freq is an alias for dump_frequency" do
330
+ expect(mount).to respond_to(:freq)
331
+ expect(mount.method(:freq)).to eq(mount.method(:dump_frequency))
332
+ end
333
+
334
+ example "mount pass_number works as expected" do
335
+ msg = 'pass_number test skipped on this platform'
336
+ skip msg if solaris || bsd || darwin
337
+ expect(mount).to respond_to(:pass_number)
338
+ expect(mount.pass_number).to be_kind_of(Numeric)
339
+ end
340
+
341
+ example "mount passno is an alias for pass_number" do
342
+ expect(mount).to respond_to(:passno)
343
+ expect(mount.method(:passno)).to eq(mount.method(:pass_number))
344
+ end
345
+
346
+ example "mount_point singleton method works as expected" do
347
+ expect(Sys::Filesystem).to respond_to(:mount_point)
348
+ expect{ Sys::Filesystem.mount_point(Dir.pwd) }.not_to raise_error
349
+ expect(Sys::Filesystem.mount_point(Dir.pwd)).to be_kind_of(String)
350
+ end
351
+
352
+ example "mount singleton method is defined" do
353
+ expect(Sys::Filesystem).to respond_to(:mount)
354
+ end
355
+
356
+ example "umount singleton method is defined" do
357
+ expect(Sys::Filesystem).to respond_to(:umount)
358
+ end
359
+ end
360
+
361
+ context "FFI" do
362
+ require 'mkmf-lite'
363
+ include Mkmf::Lite
364
+
365
+ example "ffi functions are private" do
366
+ expect(Sys::Filesystem.methods.include?('statvfs')).to be false
367
+ expect(Sys::Filesystem.methods.include?('strerror')).to be false
368
+ end
369
+
370
+ example "statfs struct is expected size" do
371
+ header = bsd || darwin ? 'sys/mount.h' : 'sys/statfs.h'
372
+ expect(Sys::Filesystem::Structs::Statfs.size).to eq(check_sizeof('struct statfs', header))
373
+ end
374
+
375
+ example "statvfs struct is expected size" do
376
+ expect(Sys::Filesystem::Structs::Statvfs.size).to eq(check_sizeof('struct statvfs', 'sys/statvfs.h'))
377
+ end
378
+
379
+ example "mnttab struct is expected size" do
380
+ skip "mnttab test skipped except on Solaris" unless solaris
381
+ expect(Sys::Filesystem::Structs::Mnttab.size).to eq(check_sizeof('struct mnttab', 'sys/mnttab.h'))
382
+ end
383
+
384
+ example "mntent struct is expected size" do
385
+ skip "mnttab test skipped except on Linux" unless linux
386
+ expect(Sys::Filesystem::Structs::Mntent.size).to eq(check_sizeof('struct mntent', 'mntent.h'))
387
+ end
388
+ end
389
+ end