summaryrefslogtreecommitdiff
path: root/spec/ruby/library/etc
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/etc')
-rw-r--r--spec/ruby/library/etc/confstr_spec.rb14
-rw-r--r--spec/ruby/library/etc/endgrent_spec.rb6
-rw-r--r--spec/ruby/library/etc/endpwent_spec.rb6
-rw-r--r--spec/ruby/library/etc/getgrent_spec.rb6
-rw-r--r--spec/ruby/library/etc/getgrgid_spec.rb87
-rw-r--r--spec/ruby/library/etc/getgrnam_spec.rb8
-rw-r--r--spec/ruby/library/etc/getlogin_spec.rb13
-rw-r--r--spec/ruby/library/etc/getpwent_spec.rb6
-rw-r--r--spec/ruby/library/etc/getpwnam_spec.rb6
-rw-r--r--spec/ruby/library/etc/getpwuid_spec.rb6
-rw-r--r--spec/ruby/library/etc/group_spec.rb19
-rw-r--r--spec/ruby/library/etc/nprocessors_spec.rb12
-rw-r--r--spec/ruby/library/etc/passwd_spec.rb15
-rw-r--r--spec/ruby/library/etc/struct_group_spec.rb10
-rw-r--r--spec/ruby/library/etc/struct_passwd_spec.rb4
-rw-r--r--spec/ruby/library/etc/sysconf_spec.rb22
-rw-r--r--spec/ruby/library/etc/sysconfdir_spec.rb8
-rw-r--r--spec/ruby/library/etc/systmpdir_spec.rb8
-rw-r--r--spec/ruby/library/etc/uname_spec.rb14
19 files changed, 183 insertions, 87 deletions
diff --git a/spec/ruby/library/etc/confstr_spec.rb b/spec/ruby/library/etc/confstr_spec.rb
new file mode 100644
index 0000000000..786cb16407
--- /dev/null
+++ b/spec/ruby/library/etc/confstr_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../spec_helper'
+require 'etc'
+
+platform_is_not :windows, :android do
+ describe "Etc.confstr" do
+ it "returns a String for Etc::CS_PATH" do
+ Etc.confstr(Etc::CS_PATH).should.instance_of?(String)
+ end
+
+ it "raises Errno::EINVAL for unknown configuration variables" do
+ -> { Etc.confstr(-1) }.should.raise(Errno::EINVAL)
+ end
+ end
+end
diff --git a/spec/ruby/library/etc/endgrent_spec.rb b/spec/ruby/library/etc/endgrent_spec.rb
index 95f0dc05e3..88de231d87 100644
--- a/spec/ruby/library/etc/endgrent_spec.rb
+++ b/spec/ruby/library/etc/endgrent_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/windows', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/windows'
require 'etc'
describe "Etc.endgrent" do
- it_behaves_like(:etc_on_windows, :endgrent)
+ it_behaves_like :etc_on_windows, :endgrent
end
diff --git a/spec/ruby/library/etc/endpwent_spec.rb b/spec/ruby/library/etc/endpwent_spec.rb
index 7ce8f1925b..e4e564d251 100644
--- a/spec/ruby/library/etc/endpwent_spec.rb
+++ b/spec/ruby/library/etc/endpwent_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/windows', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/windows'
require 'etc'
describe "Etc.endpwent" do
- it_behaves_like(:etc_on_windows, :endpwent)
+ it_behaves_like :etc_on_windows, :endpwent
end
diff --git a/spec/ruby/library/etc/getgrent_spec.rb b/spec/ruby/library/etc/getgrent_spec.rb
index 96225e351a..45a4442262 100644
--- a/spec/ruby/library/etc/getgrent_spec.rb
+++ b/spec/ruby/library/etc/getgrent_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/windows', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/windows'
require 'etc'
describe "Etc.getgrent" do
- it_behaves_like(:etc_on_windows, :getgrent)
+ it_behaves_like :etc_on_windows, :getgrent
end
diff --git a/spec/ruby/library/etc/getgrgid_spec.rb b/spec/ruby/library/etc/getgrgid_spec.rb
index 9b6b283d52..472d4c82c8 100644
--- a/spec/ruby/library/etc/getgrgid_spec.rb
+++ b/spec/ruby/library/etc/getgrgid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
platform_is :windows do
@@ -13,58 +13,57 @@ end
# TODO: verify these on non-windows, non-darwin OS
platform_is_not :windows do
- describe "Etc.getgrgid" do
- before :all do
- @gid = `id -g`.strip.to_i
- @name = `id -gn`.strip
- end
+ grpname = nil
+ guard -> {
+ grpname = IO.popen(%w'id -gn', err: IO::NULL, &:read).chomp
+ $?.success?
+ } do
+ describe "Etc.getgrgid" do
+ before :all do
+ @gid = `id -g`.strip.to_i
+ @name = grpname
+ end
- it "returns a Etc::Group struct instance for the given user" do
- gr = Etc.getgrgid(@gid)
+ it "returns a Etc::Group struct instance for the given user" do
+ gr = Etc.getgrgid(@gid)
- gr.is_a?(Etc::Group).should == true
- gr.gid.should == @gid
- gr.name.should == @name
- end
+ gr.is_a?(Etc::Group).should == true
+ gr.gid.should == @gid
+ gr.name.should == @name
+ end
- it "returns the Etc::Group for a given gid if it exists" do
- grp = Etc.getgrgid(@gid)
- grp.should be_kind_of(Etc::Group)
- grp.gid.should == @gid
- grp.name.should == @name
- end
+ it "returns the Etc::Group for a given gid if it exists" do
+ grp = Etc.getgrgid(@gid)
+ grp.should.is_a?(Etc::Group)
+ grp.gid.should == @gid
+ grp.name.should == @name
+ end
- it "uses Process.gid as the default value for the argument" do
- gr = Etc.getgrgid
+ it "uses Process.gid as the default value for the argument" do
+ gr = Etc.getgrgid
- gr.gid.should == @gid
- gr.name.should == @name
- end
+ gr.gid.should == @gid
+ gr.name.should == @name
+ end
- it "returns the Group for a given gid if it exists" do
- grp = Etc.getgrgid(@gid)
- grp.should be_kind_of(Struct::Group)
- grp.gid.should == @gid
- grp.name.should == @name
- end
-
- it "raises if the group does not exist" do
- lambda { Etc.getgrgid(9876)}.should raise_error(ArgumentError)
- end
+ it "raises if the group does not exist" do
+ -> { Etc.getgrgid(9876)}.should.raise(ArgumentError)
+ end
- it "raises a TypeError if not passed an Integer" do
- lambda { Etc.getgrgid("foo") }.should raise_error(TypeError)
- lambda { Etc.getgrgid(nil) }.should raise_error(TypeError)
- end
+ it "raises a TypeError if not passed an Integer" do
+ -> { Etc.getgrgid("foo") }.should.raise(TypeError)
+ -> { Etc.getgrgid(nil) }.should.raise(TypeError)
+ end
- it "can be called safely by multiple threads" do
- 20.times.map do
- Thread.new do
- 100.times do
- Etc.getgrgid(@gid).gid.should == @gid
+ it "can be called safely by multiple threads" do
+ 20.times.map do
+ Thread.new do
+ 100.times do
+ Etc.getgrgid(@gid).gid.should == @gid
+ end
end
- end
- end.each(&:join)
+ end.each(&:join)
+ end
end
end
end
diff --git a/spec/ruby/library/etc/getgrnam_spec.rb b/spec/ruby/library/etc/getgrnam_spec.rb
index 46193f49d6..325ea7b297 100644
--- a/spec/ruby/library/etc/getgrnam_spec.rb
+++ b/spec/ruby/library/etc/getgrnam_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
platform_is :windows do
@@ -11,7 +11,7 @@ platform_is :windows do
end
end
-platform_is_not :windows do
+platform_is_not :windows, :android do
describe "Etc.getgrnam" do
it "returns a Etc::Group struct instance for the given group" do
gr_name = Etc.getgrent.name
@@ -21,10 +21,10 @@ platform_is_not :windows do
end
it "only accepts strings as argument" do
- lambda {
+ -> {
Etc.getgrnam(123)
Etc.getgrnam(nil)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
end
diff --git a/spec/ruby/library/etc/getlogin_spec.rb b/spec/ruby/library/etc/getlogin_spec.rb
index 43e654bda6..2bc598c0af 100644
--- a/spec/ruby/library/etc/getlogin_spec.rb
+++ b/spec/ruby/library/etc/getlogin_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
describe "Etc.getlogin" do
@@ -14,16 +14,21 @@ describe "Etc.getlogin" do
if ENV['TRAVIS'] and platform_is(:darwin)
# See https://travis-ci.org/ruby/spec/jobs/285967744
# and https://travis-ci.org/ruby/spec/jobs/285999602
- Etc.getlogin.should be_an_instance_of(String)
+ Etc.getlogin.should.instance_of?(String)
else
# Etc.getlogin returns the same result of logname(2)
# if it returns non NULL
- Etc.getlogin.should == `id -un`.chomp
+ if system("which logname", out: File::NULL, err: File::NULL)
+ Etc.getlogin.should == `logname`.chomp
+ else
+ # fallback to `id` command since `logname` is not available
+ Etc.getlogin.should == `id -un`.chomp
+ end
end
else
# Etc.getlogin may return nil if the login name is not set
# because of chroot or sudo or something.
- Etc.getlogin.should be_nil
+ Etc.getlogin.should == nil
getlogin_null = true
end
ensure
diff --git a/spec/ruby/library/etc/getpwent_spec.rb b/spec/ruby/library/etc/getpwent_spec.rb
index 1c8057c9e5..9a911aed8f 100644
--- a/spec/ruby/library/etc/getpwent_spec.rb
+++ b/spec/ruby/library/etc/getpwent_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/windows', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/windows'
require 'etc'
describe "Etc.getpwent" do
- it_behaves_like(:etc_on_windows, :getpwent)
+ it_behaves_like :etc_on_windows, :getpwent
end
diff --git a/spec/ruby/library/etc/getpwnam_spec.rb b/spec/ruby/library/etc/getpwnam_spec.rb
index 8610b5da91..a0b3c9e1fe 100644
--- a/spec/ruby/library/etc/getpwnam_spec.rb
+++ b/spec/ruby/library/etc/getpwnam_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
platform_is :windows do
@@ -19,10 +19,10 @@ platform_is_not :windows do
end
it "only accepts strings as argument" do
- lambda {
+ -> {
Etc.getpwnam(123)
Etc.getpwnam(nil)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
end
diff --git a/spec/ruby/library/etc/getpwuid_spec.rb b/spec/ruby/library/etc/getpwuid_spec.rb
index f1c7218c0b..3e35dfe6d5 100644
--- a/spec/ruby/library/etc/getpwuid_spec.rb
+++ b/spec/ruby/library/etc/getpwuid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
platform_is :windows do
@@ -27,10 +27,10 @@ platform_is_not :windows do
end
it "only accepts integers as argument" do
- lambda {
+ -> {
Etc.getpwuid("foo")
Etc.getpwuid(nil)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
end
diff --git a/spec/ruby/library/etc/group_spec.rb b/spec/ruby/library/etc/group_spec.rb
index 8b92cb7bf0..d7addbbec1 100644
--- a/spec/ruby/library/etc/group_spec.rb
+++ b/spec/ruby/library/etc/group_spec.rb
@@ -1,18 +1,27 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/windows', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/windows'
require 'etc'
describe "Etc.group" do
- it_behaves_like(:etc_on_windows, :group)
+ it_behaves_like :etc_on_windows, :group
+
+ platform_is_not :windows, :android do
+ it "returns a Etc::Group struct" do
+ group = Etc.group
+ begin
+ group.should.instance_of?(Etc::Group)
+ ensure
+ Etc.endgrent
+ end
+ end
- platform_is_not :windows do
it "raises a RuntimeError for parallel iteration" do
proc {
Etc.group do | group |
Etc.group do | group2 |
end
end
- }.should raise_error(RuntimeError)
+ }.should.raise(RuntimeError)
end
end
end
diff --git a/spec/ruby/library/etc/nprocessors_spec.rb b/spec/ruby/library/etc/nprocessors_spec.rb
index bce11d06c5..482719dde0 100644
--- a/spec/ruby/library/etc/nprocessors_spec.rb
+++ b/spec/ruby/library/etc/nprocessors_spec.rb
@@ -1,11 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
-ruby_version_is "2.2" do
- describe "Etc.nprocessors" do
- it "returns the number of online processors" do
- Etc.nprocessors.should be_kind_of(Integer)
- Etc.nprocessors.should >= 1
- end
+describe "Etc.nprocessors" do
+ it "returns the number of online processors" do
+ Etc.nprocessors.should.is_a?(Integer)
+ Etc.nprocessors.should >= 1
end
end
diff --git a/spec/ruby/library/etc/passwd_spec.rb b/spec/ruby/library/etc/passwd_spec.rb
new file mode 100644
index 0000000000..0602b7e10b
--- /dev/null
+++ b/spec/ruby/library/etc/passwd_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../../spec_helper'
+require 'etc'
+
+platform_is_not :windows do
+ describe "Etc.passwd" do
+ it "returns a Etc::Passwd struct" do
+ passwd = Etc.passwd
+ begin
+ passwd.should.instance_of?(Etc::Passwd)
+ ensure
+ Etc.endpwent
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/etc/struct_group_spec.rb b/spec/ruby/library/etc/struct_group_spec.rb
index c33a177a98..b2147e306d 100644
--- a/spec/ruby/library/etc/struct_group_spec.rb
+++ b/spec/ruby/library/etc/struct_group_spec.rb
@@ -1,14 +1,18 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
-describe "Struct::Group" do
+describe "Etc::Group" do
platform_is_not :windows do
+ grpname = IO.popen(%w'id -gn', err: IO::NULL, &:read)
+ next unless $?.success?
+ grpname.chomp!
+
before :all do
@g = Etc.getgrgid(`id -g`.strip.to_i)
end
it "returns group name" do
- @g.name.should == `id -gn`.strip
+ @g.name.should == grpname
end
it "returns group password" do
diff --git a/spec/ruby/library/etc/struct_passwd_spec.rb b/spec/ruby/library/etc/struct_passwd_spec.rb
index 3e4bfee828..dc37c17e7d 100644
--- a/spec/ruby/library/etc/struct_passwd_spec.rb
+++ b/spec/ruby/library/etc/struct_passwd_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
-describe "Struct::Passwd" do
+describe "Etc::Passwd" do
platform_is_not :windows do
before :all do
@pw = Etc.getpwuid(`id -u`.strip.to_i)
diff --git a/spec/ruby/library/etc/sysconf_spec.rb b/spec/ruby/library/etc/sysconf_spec.rb
new file mode 100644
index 0000000000..81ce1ca258
--- /dev/null
+++ b/spec/ruby/library/etc/sysconf_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../spec_helper'
+require 'etc'
+
+platform_is_not :windows do
+ describe "Etc.sysconf" do
+ %w[
+ SC_ARG_MAX SC_CHILD_MAX SC_HOST_NAME_MAX SC_LOGIN_NAME_MAX SC_NGROUPS_MAX
+ SC_CLK_TCK SC_OPEN_MAX SC_PAGESIZE SC_RE_DUP_MAX SC_STREAM_MAX
+ SC_SYMLOOP_MAX SC_TTY_NAME_MAX SC_TZNAME_MAX SC_VERSION
+ ].each do |const|
+ it "returns the value of POSIX.1 system configuration variable #{const}" do
+ var = Etc.const_get(const)
+ value = Etc.sysconf(var)
+ if value.nil?
+ value.should == nil
+ else
+ value.should.is_a?(Integer)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/etc/sysconfdir_spec.rb b/spec/ruby/library/etc/sysconfdir_spec.rb
new file mode 100644
index 0000000000..eb2d6b649a
--- /dev/null
+++ b/spec/ruby/library/etc/sysconfdir_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+require 'etc'
+
+describe "Etc.sysconfdir" do
+ it "returns a String" do
+ Etc.sysconfdir.should.instance_of?(String)
+ end
+end
diff --git a/spec/ruby/library/etc/systmpdir_spec.rb b/spec/ruby/library/etc/systmpdir_spec.rb
new file mode 100644
index 0000000000..ed34cb43fc
--- /dev/null
+++ b/spec/ruby/library/etc/systmpdir_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+require 'etc'
+
+describe "Etc.systmpdir" do
+ it "returns a String" do
+ Etc.systmpdir.should.instance_of?(String)
+ end
+end
diff --git a/spec/ruby/library/etc/uname_spec.rb b/spec/ruby/library/etc/uname_spec.rb
new file mode 100644
index 0000000000..1c5fe2a741
--- /dev/null
+++ b/spec/ruby/library/etc/uname_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../spec_helper'
+require 'etc'
+
+describe "Etc.uname" do
+ it "returns a Hash with the documented keys" do
+ uname = Etc.uname
+ uname.should.is_a?(Hash)
+ uname.should.key?(:sysname)
+ uname.should.key?(:nodename)
+ uname.should.key?(:release)
+ uname.should.key?(:version)
+ uname.should.key?(:machine)
+ end
+end