os 0.7.4 → 0.8.0

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.
data/.autotest ADDED
@@ -0,0 +1,14 @@
1
+ # autotest config for rspec
2
+ # see: https://github.com/rspec/rspec/wiki/autotest
3
+ Autotest.add_hook(:initialize) {|at|
4
+ at.add_exception %r{^\.git} # ignore Version Control System
5
+ at.add_exception %r{^pkg} # ignore gem pkg dir
6
+ # at.add_exception %r{^./tmp} # ignore temp files, lest autotest will run again, and again...
7
+ # at.clear_mappings # take out the default (test/test*rb)
8
+ ## include specs
9
+ at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
10
+ Dir['spec/**/*_spec.rb']
11
+ }
12
+ nil
13
+ }
14
+
data/.document CHANGED
@@ -1,5 +1,5 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ os (0.7.4)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.2)
10
+ git (1.2.5)
11
+ jeweler (1.6.0)
12
+ bundler (~> 1.0.0)
13
+ git (>= 1.2.5)
14
+ rake
15
+ rake (0.8.7)
16
+ rspec (2.5.0)
17
+ rspec-core (~> 2.5.0)
18
+ rspec-expectations (~> 2.5.0)
19
+ rspec-mocks (~> 2.5.0)
20
+ rspec-core (2.5.1)
21
+ rspec-expectations (2.5.0)
22
+ diff-lcs (~> 1.1.2)
23
+ rspec-mocks (2.5.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ jeweler
30
+ os!
31
+ rspec (>= 2.0)
data/README.rdoc CHANGED
@@ -1,47 +1,62 @@
1
- The OS gem allows for some easy telling if you're on windows or not.
2
-
3
- require 'os'
4
- >> OS.windows?
5
- => true # also OS.doze?
6
-
7
- >> OS.bits
8
- => 32
9
-
10
- >> OS.java?
11
- => true # if you're running in jruby also OS.jruby?
12
-
13
- >> OS.ruby_bin
14
- => "c:\ruby18\bin\ruby.exe" # or "/usr/local/bin/ruby" or what not
15
-
16
- >> OS.posix?
17
- => false
18
-
19
- >> OS.mac?
20
- => false
21
-
22
- >> OS.java? # same as OS.jruby?
23
- => true
24
-
25
- >> OS.dev_null
26
- => "NUL" # or "/dev/null" depending on which platform
27
-
28
- >> OS.rss_bytes
29
- => 12300033 # rss bytes this process is using currently, works in Linux/windows
30
-
31
- If there are any other features you'd like, let me know.
32
-
33
- github.com/rdp/os for feedback et al
34
-
35
- Related projects:
36
-
37
- rubygems:
38
- Gem::Platform.local
39
- Gem.ruby
40
-
41
- facets gem (similar to rubygems, above)
42
- require 'facets/platform'
43
- Platform.local
44
-
45
- the "platform" gem, itself (different gem)
46
-
47
- The reason Gem::Platform.local felt wrong to me is that it treated cygwin as windows--which for most build environments, is wrong.
1
+ The OS gem allows for some easy telling if you're on windows or not.
2
+
3
+ require 'os'
4
+
5
+ >> OS.windows?
6
+ => true # also OS.doze?
7
+
8
+ >> OS.bits
9
+ => 32
10
+
11
+ >> OS.java?
12
+ => true # if you're running in jruby also OS.jruby?
13
+
14
+ >> OS.ruby_bin
15
+ => "c:\ruby18\bin\ruby.exe" # or "/usr/local/bin/ruby" or what not
16
+
17
+ >> OS.posix?
18
+ => false
19
+
20
+ >> OS.mac?
21
+ => false
22
+
23
+ >> OS.java? # same as OS.jruby?
24
+ => true
25
+
26
+ >> OS.dev_null
27
+ => "NUL" # or "/dev/null" depending on which platform
28
+
29
+ >> OS.rss_bytes
30
+ => 12300033 # rss bytes this process is using currently, works in Linux/windows
31
+
32
+ >> puts OS.report
33
+ ==> # a yaml report of helpful values
34
+ ---
35
+ arch: x86_64-darwin10.6.0
36
+ target_os: darwin10.6.0
37
+ target_vendor: apple
38
+ target_cpu: x86_64
39
+ target: x86_64-apple-darwin10.6.0
40
+ host_os: darwin10.6.0
41
+ host_vendor: apple
42
+ host_cpu: i386
43
+ host: i386-apple-darwin10.6.0
44
+ RUBY_PLATFORM: x86_64-darwin10.6.0
45
+
46
+ If there are any other features you'd like, let me know.
47
+
48
+ github.com/rdp/os for feedback et al
49
+
50
+ Related projects:
51
+
52
+ rubygems:
53
+ Gem::Platform.local
54
+ Gem.ruby
55
+
56
+ facets gem (similar to rubygems, above)
57
+ require 'facets/platform'
58
+ Platform.local
59
+
60
+ the "platform" gem, itself (different gem)
61
+
62
+ The reason Gem::Platform.local felt wrong to me is that it treated cygwin as windows--which for most build environments, is wrong.
data/Rakefile CHANGED
@@ -1,26 +1,24 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
-
5
- begin
6
- # require 'psych'
7
- rescue ::LoadError
8
- end
9
-
10
- begin
11
- require 'jeweler'
12
- Jeweler::Tasks.new do |gem|
13
- gem.name = "os"
14
- gem.summary = %Q{Simple and easy way to know if you're on windows or not (reliably), as well as how many bits the OS is, etc.}
15
- gem.description = %Q{The OS gem allows for some useful and easy functions, like OS.windows? (=> true or false) OS.bits ( => 32 or 64) etc"}
16
- gem.email = "rogerpack2005@gmail.com"
17
- gem.homepage = "http://github.com/rdp/os"
18
- gem.authors = ["rdp", "David McCullars"]
19
- gem.add_development_dependency "rspec", ">= 2.0"
20
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
21
- gem.add_development_dependency "sane"
22
- # gem.add_development_dependency "fast_require"
23
- end
24
- rescue LoadError
25
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
26
- end
1
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "os"
8
+ gem.summary = %Q{Simple and easy way to know if you're on windows or not (reliably), as well as how many bits the OS is, etc.}
9
+ gem.description = %Q{The OS gem allows for some useful and easy functions, like OS.windows? (=> true or false) OS.bits ( => 32 or 64) etc"}
10
+ gem.email = "rogerpack2005@gmail.com"
11
+ gem.homepage = "http://github.com/rdp/os"
12
+ gem.authors = ["rdp", "David McCullars"]
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ # gem.add_development_dependency "fast_require"
15
+ gem.add_development_dependency "rspec", ">= 2.0"
16
+ end
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rspec/core/rake_task'
22
+ RSpec::Core::RakeTask.new(:spec)
23
+ task :default => :spec
24
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.4
1
+ 0.8.0
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
data/lib/os.rb CHANGED
@@ -1,172 +1,218 @@
1
- # a set of friendly files for determining your Ruby runtime
2
- # treats cygwin as linux
3
- # also treats IronRuby on mono as...linux
4
- class OS
5
-
6
- # true if on windows [and/or jruby]
7
- # false if on linux or cygwin on windows
8
-
9
- def self.windows?
10
- @windows ||= begin
11
- if RUBY_PLATFORM =~ /cygwin/ # i386-cygwin
12
- false
13
- elsif ENV['OS'] == 'Windows_NT'
14
- true
15
- else
16
- false
17
- end
18
- end
19
-
20
- end
21
-
22
- # true for linux, os x, cygwin
23
- def self.posix?
24
- @posix ||=
25
- begin
26
- if OS.windows?
27
- begin
28
- begin
29
- # what if we're on interix...
30
- # untested, of course
31
- Process.wait fork{}
32
- true
33
- rescue NotImplementedError, NoMethodError
34
- false
35
- end
36
- end
37
- else
38
- # assume non windows is posix
39
- true
40
- end
41
- end
42
-
43
- end
44
-
45
- def self.iron_ruby?
46
- @iron_ruby ||= begin
47
- if defined?(RUBY_ENGINE) && (RUBY_ENGINE == 'ironruby')
48
- true
49
- else
50
- false
51
- end
52
- end
53
- end
54
-
55
- def self.bits
56
- @bits ||= begin
57
- require 'rbconfig'
58
- host_cpu = RbConfig::CONFIG['host_cpu']
59
- if host_cpu =~ /_64$/ # x86_64
60
- 64
61
- elsif RUBY_PLATFORM == 'java' && ENV_JAVA['sun.arch.data.model'] # "32" or "64":http://www.ruby-forum.com/topic/202173#880613
62
- ENV_JAVA['sun.arch.data.model'].to_i
63
- elsif host_cpu == 'i386'
64
- 32
65
- elsif RbConfig::CONFIG['host_os'] =~ /32$/ # mingw32, mswin32
66
- 32
67
- else # cygwin only...I think
68
- if 1.size == 8
69
- 64
70
- else
71
- 32
72
- end
73
- end
74
- end
75
- end
76
-
77
-
78
- def self.java?
79
- @java ||= begin
80
- if RUBY_PLATFORM =~ /java/
81
- true
82
- else
83
- false
84
- end
85
- end
86
- end
87
-
88
- def self.ruby_bin
89
- @ruby_exe ||= begin
90
- require 'rbconfig'
91
- config = RbConfig::CONFIG
92
- File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
93
- end
94
- end
95
-
96
- def self.mac?
97
- @mac = begin
98
- if RUBY_PLATFORM =~ /darwin/
99
- true
100
- else
101
- false
102
- end
103
- end
104
- end
105
-
106
- # amount of memory the current process "is using", in RAM
107
- # (doesn't include any swap memory that it may be using, just that in actual RAM)
108
- # raises 'unknown' on jruby currently
109
- def self.rss_bytes
110
- # attempt to do this in a jruby friendly way
111
- if OS::Underlying.windows?
112
- # MRI, Java, IronRuby, Cygwin
113
- if OS.java?
114
- # no win32ole on 1.5.x, so leave here for compatibility...maybe for awhile :P
115
- require 'java'
116
- mem_bean = java.lang.management.ManagementFactory.getMemoryMXBean
117
- mem_bean.heap_memory_usage.used + mem_bean.non_heap_memory_usage.used
118
- else
119
- wmi = nil
120
- begin
121
- require 'win32ole'
122
- wmi = WIN32OLE.connect("winmgmts://")
123
- rescue LoadError, NoMethodError => e # NoMethod for IronRuby currently [sigh]
124
- raise 'rss unknown for this platform ' + e.to_s
125
- end
126
- processes = wmi.ExecQuery("select * from win32_process where ProcessId = #{Process.pid}")
127
- memory_used = nil
128
- # only allow for one...
129
- for process in processes; raise if memory_used; memory_used = process.WorkingSetSize.to_i; end
130
- memory_used
131
- end
132
- elsif OS.posix? # linux [though I've heard it works in OS X]
133
- kb = `ps -o rss= -p #{Process.pid}`.to_i # in kilobytes
134
- else
135
- raise 'unknown rss for this platform'
136
- end
137
- end
138
-
139
- class Underlying
140
-
141
- def self.windows?
142
- ENV['OS'] == 'Windows_NT'
143
- end
144
-
145
- end
146
-
147
- def self.cygwin?
148
- @cygwin = begin
149
- if RUBY_PLATFORM =~ /-cygwin/
150
- true
151
- else
152
- false
153
- end
154
- end
155
- end
156
-
157
- def self.dev_null
158
- @dev_null ||= begin
159
- if OS.windows?
160
- "NUL"
161
- else
162
- "/dev/null"
163
- end
164
- end
165
- end
166
-
167
- class << self
168
- alias :doze? :windows? # a joke name but I use it and like it :P
169
- alias :jruby? :java?
170
- end
171
-
172
- end
1
+ require 'rbconfig'
2
+ require 'yaml'
3
+
4
+ # a set of friendly files for determining your Ruby runtime
5
+ # treats cygwin as linux
6
+ # also treats IronRuby on mono as...linux
7
+ class OS
8
+ attr_reader :config
9
+
10
+ def self.config
11
+ @config ||= RbConfig::CONFIG
12
+ end
13
+
14
+ # true if on windows [and/or jruby]
15
+ # false if on linux or cygwin on windows
16
+
17
+ def self.windows?
18
+ @windows ||= begin
19
+ if RUBY_PLATFORM =~ /cygwin/ # i386-cygwin
20
+ false
21
+ elsif ENV['OS'] == 'Windows_NT'
22
+ true
23
+ else
24
+ false
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ # true for linux, os x, cygwin
31
+ def self.posix?
32
+ @posix ||=
33
+ begin
34
+ if OS.windows?
35
+ begin
36
+ begin
37
+ # what if we're on interix...
38
+ # untested, of course
39
+ Process.wait fork{}
40
+ true
41
+ rescue NotImplementedError, NoMethodError
42
+ false
43
+ end
44
+ end
45
+ else
46
+ # assume non windows is posix
47
+ true
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ # true for linux, false for windows, os x, cygwin
54
+ def self.linux?
55
+ if (host_os =~ /linux/)
56
+ true
57
+ else
58
+ false
59
+ end
60
+ end
61
+
62
+ def self.iron_ruby?
63
+ @iron_ruby ||= begin
64
+ if defined?(RUBY_ENGINE) && (RUBY_ENGINE == 'ironruby')
65
+ true
66
+ else
67
+ false
68
+ end
69
+ end
70
+ end
71
+
72
+ def self.bits
73
+ @bits ||= begin
74
+ if host_cpu =~ /_64$/ || RUBY_PLATFORM =~ /x86_64/
75
+ 64
76
+ elsif RUBY_PLATFORM == 'java' && ENV_JAVA['sun.arch.data.model'] # "32" or "64":http://www.ruby-forum.com/topic/202173#880613
77
+ ENV_JAVA['sun.arch.data.model'].to_i
78
+ elsif host_cpu == 'i386'
79
+ 32
80
+ elsif host_os =~ /32$/ # mingw32, mswin32
81
+ 32
82
+ else # cygwin only...I think
83
+ if 1.size == 8
84
+ 64
85
+ else
86
+ 32
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+
93
+ def self.java?
94
+ @java ||= begin
95
+ if RUBY_PLATFORM =~ /java/
96
+ true
97
+ else
98
+ false
99
+ end
100
+ end
101
+ end
102
+
103
+ def self.ruby_bin
104
+ @ruby_exe ||= begin
105
+ File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
106
+ end
107
+ end
108
+
109
+ def self.mac?
110
+ @mac = begin
111
+ if host_os =~ /darwin/
112
+ true
113
+ else
114
+ false
115
+ end
116
+ end
117
+ end
118
+
119
+ def self.osx?
120
+ mac?
121
+ end
122
+
123
+ # amount of memory the current process "is using", in RAM
124
+ # (doesn't include any swap memory that it may be using, just that in actual RAM)
125
+ # raises 'unknown' on jruby currently
126
+ def self.rss_bytes
127
+ # attempt to do this in a jruby friendly way
128
+ if OS::Underlying.windows?
129
+ # MRI, Java, IronRuby, Cygwin
130
+ if OS.java?
131
+ # no win32ole on 1.5.x, so leave here for compatibility...maybe for awhile :P
132
+ require 'java'
133
+ mem_bean = java.lang.management.ManagementFactory.getMemoryMXBean
134
+ mem_bean.heap_memory_usage.used + mem_bean.non_heap_memory_usage.used
135
+ else
136
+ wmi = nil
137
+ begin
138
+ require 'win32ole'
139
+ wmi = WIN32OLE.connect("winmgmts://")
140
+ rescue LoadError, NoMethodError => e # NoMethod for IronRuby currently [sigh]
141
+ raise 'rss unknown for this platform ' + e.to_s
142
+ end
143
+ processes = wmi.ExecQuery("select * from win32_process where ProcessId = #{Process.pid}")
144
+ memory_used = nil
145
+ # only allow for one...
146
+ for process in processes; raise if memory_used; memory_used = process.WorkingSetSize.to_i; end
147
+ memory_used
148
+ end
149
+ elsif OS.posix? # linux [though I've heard it works in OS X]
150
+ kb = `ps -o rss= -p #{Process.pid}`.to_i # in kilobytes
151
+ else
152
+ raise 'unknown rss for this platform'
153
+ end
154
+ end
155
+
156
+ class Underlying
157
+
158
+ def self.bsd?
159
+ OS.osx?
160
+ end
161
+
162
+ def self.windows?
163
+ ENV['OS'] == 'Windows_NT'
164
+ end
165
+
166
+ def self.linux?
167
+ OS.host_os =~ /linux/ ? true : false
168
+ end
169
+
170
+ end
171
+
172
+ def self.cygwin?
173
+ @cygwin = begin
174
+ if RUBY_PLATFORM =~ /-cygwin/
175
+ true
176
+ else
177
+ false
178
+ end
179
+ end
180
+ end
181
+
182
+ def self.dev_null
183
+ @dev_null ||= begin
184
+ if OS.windows?
185
+ "NUL"
186
+ else
187
+ "/dev/null"
188
+ end
189
+ end
190
+ end
191
+
192
+ # provides easy way to see the relevant config entries
193
+ def self.report
194
+ relevant_keys = [
195
+ 'arch',
196
+ 'host',
197
+ 'host_cpu',
198
+ 'host_os',
199
+ 'host_vendor',
200
+ 'target',
201
+ 'target_cpu',
202
+ 'target_os',
203
+ 'target_vendor',
204
+ ]
205
+ RbConfig::CONFIG.reject {|key, val| !relevant_keys.include? key }.merge({'RUBY_PLATFORM' => RUBY_PLATFORM}).to_yaml
206
+ end
207
+
208
+ class << self
209
+ alias :doze? :windows? # a joke name but I use it and like it :P
210
+ alias :jruby? :java?
211
+
212
+ # delegators for relevant config values
213
+ %w(host host_cpu host_os).each do |method_name|
214
+ define_method(method_name) { config[method_name] }
215
+ end
216
+ end
217
+
218
+ end
data/os.gemspec ADDED
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{os}
8
+ s.version = "0.8.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["rdp", "David McCullars"]
12
+ s.date = %q{2011-05-19}
13
+ s.description = %q{The OS gem allows for some useful and easy functions, like OS.windows? (=> true or false) OS.bits ( => 32 or 64) etc"}
14
+ s.email = %q{rogerpack2005@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".autotest",
20
+ ".document",
21
+ ".gitignore",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "autotest/discover.rb",
28
+ "lib/os.rb",
29
+ "os.gemspec",
30
+ "spec/linux_spec.rb",
31
+ "spec/os_spec.rb",
32
+ "spec/osx_spec.rb",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/rdp/os}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{Simple and easy way to know if you're on windows or not (reliably), as well as how many bits the OS is, etc.}
40
+ s.test_files = [
41
+ "spec/linux_spec.rb",
42
+ "spec/osx_spec.rb",
43
+ "spec/os_spec.rb",
44
+ "spec/spec_helper.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
+ s.add_development_dependency(%q<rspec>, [">= 2.0"])
53
+ else
54
+ s.add_dependency(%q<rspec>, [">= 2.0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<rspec>, [">= 2.0"])
58
+ end
59
+ end
60
+
@@ -0,0 +1,38 @@
1
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
2
+
3
+ require File.dirname(__FILE__) + '/../lib/os.rb' # load before sane to avoid sane being able to requir the gemified version...
4
+ require 'rspec' # rspec2
5
+
6
+ describe 'For Linux, (Ubuntu, Ubuntu 10.04 LTS) ' do
7
+ before(:each) do
8
+ ENV.should_receive(:[]).with('OS').any_number_of_times.and_return()
9
+ ## Having difficulties finding a stub for RUBY_PLATFORM
10
+ # Looking into something like: http://stackoverflow.com/questions/1698335/can-i-use-rspec-mocks-to-stub-out-version-constants
11
+ # For now, simply using RbConfig::CONFIG
12
+ # Kernel.stub!(:const_get).with('RUBY_PLATFORM').and_return("i686-linux")
13
+ RbConfig::CONFIG.stub!(:[]).with('host_os').and_return('linux_gnu')
14
+ RbConfig::CONFIG.stub!(:[]).with('host_cpu').and_return('i686')
15
+ end
16
+
17
+ describe OS do
18
+ subject { OS } # class, not instance
19
+
20
+ it { should be_linux }
21
+ it { should be_posix }
22
+
23
+ it { should_not be_mac }
24
+ it { should_not be_osx }
25
+ it { should_not be_windows }
26
+
27
+ end
28
+
29
+ describe OS::Underlying do
30
+ subject { OS::Underlying } # class, not instance
31
+
32
+ it { should be_linux }
33
+
34
+ it { should_not be_bsd }
35
+ it { should_not be_windows }
36
+ end
37
+ end
38
+
@@ -1,122 +1,145 @@
1
- require 'rubygems' if RUBY_VERSION < '1.9.0'
2
-
3
- require File.dirname(__FILE__) + '/../lib/os.rb' # load before sane to avoid sane being able to requir the gemified version...
4
- require 'sane'
5
- load File.dirname(__FILE__) + '/../lib/os.rb' # just in case
6
- require 'rspec' # rspec2
7
-
8
- describe "OS" do
9
-
10
- it "has a windows? method" do
11
- if ENV['OS'] == 'Windows_NT'
12
- unless RUBY_PLATFORM =~ /cygwin/
13
- assert OS.windows? == true
14
- assert OS.doze? == true
15
- assert OS.posix? == false
16
- else
17
- assert OS::Underlying.windows?
18
- assert OS.windows? == false
19
- assert OS.posix? == true
20
- end
21
- assert OS::Underlying.windows?
22
- elsif (RbConfig::CONFIG["host_os"] == 'linux') || RUBY_PLATFORM =~ /linux/
23
- assert OS.windows? == false
24
- assert OS.posix? == true
25
- assert !OS::Underlying.windows?
26
- else
27
- pending "create test"
28
- end
29
- end
30
-
31
- it "has a bits method" do
32
- if RUBY_PLATFORM =~ /mingw32/
33
- assert OS.bits == 32
34
- elsif RUBY_PLATFORM =~ /64/ # linux...
35
- assert OS.bits == 64
36
- elsif RUBY_PLATFORM =~ /i686/
37
- assert OS.bits == 32
38
- elsif RUBY_PLATFORM =~ /java/ && RbConfig::CONFIG['host_os'] =~ /32$/
39
- assert OS.bits == 32
40
- elsif RUBY_PLATFORM =~ /java/ && RbConfig::CONFIG['host_cpu'] =~ /i386/
41
- assert OS.bits == 32
42
- elsif RUBY_PLATFORM =~ /i386/
43
- assert OS.bits == 32
44
- else
45
- pending "os bits not tested!" + RUBY_PLATFORM + ' ' + RbConfig::CONFIG['host_os']
46
- end
47
-
48
- end
49
-
50
- it "should have an iron_ruby method" do
51
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ironruby'
52
- assert OS.iron_ruby? == true
53
- else
54
- assert OS.iron_ruby? == false
55
- end
56
- end
57
-
58
- it "should know if you're on java" do
59
- if RUBY_PLATFORM == 'java'
60
- assert OS.java? == true # must be [true | false]
61
- else
62
- assert OS.java? == false
63
- end
64
- end
65
-
66
- it "should have a ruby_bin method" do
67
- if OS.windows?
68
- assert OS.ruby_bin.include?('.exe')
69
- if OS.iron_ruby?
70
- assert OS.ruby_bin.include?('ir.exe')
71
- else
72
- assert OS.ruby_bin.include?('ruby.exe')
73
- end
74
- else
75
- assert OS.ruby_bin.include?('ruby') && OS.ruby_bin.include?('/')
76
- end
77
-
78
- if OS.java?
79
- assert OS.ruby_bin.include?('jruby') # I think
80
- end
81
-
82
- end
83
-
84
- it "should have a cygwin? method" do
85
- if RUBY_PLATFORM =~ /cygwin/
86
- assert OS.cygwin? == true
87
- else
88
- assert OS.cygwin? == false
89
- end
90
- end
91
-
92
- it "should have a functional mac? method" do
93
- if RUBY_PLATFORM =~ /darwin/
94
- assert OS.mac? == true
95
- else
96
- assert OS.mac? == false
97
- end
98
- end
99
-
100
- it "should have a way to get rss_bytes on each platform" do
101
- bytes = OS.rss_bytes
102
- assert bytes > 0 # should always be true
103
- assert bytes.is_a?(Numeric) # don't want strings from any platform...
104
- end
105
-
106
- it "should tell you what the right /dev/null is" do
107
- if OS.windows?
108
- OS.dev_null.should == "NUL"
109
- else
110
- OS.dev_null.should == "/dev/null"
111
- end
112
- end
113
-
114
- it "should have a jruby method" do
115
- if RUBY_DESCRIPTION =~ /^(jruby|java)/
116
- assert OS.jruby?
117
- else
118
- assert !OS.jruby?
119
- end
120
- end
121
-
122
- end
1
+ require File.expand_path('spec_helper.rb', File.dirname(__FILE__))
2
+
3
+ describe "OS" do
4
+
5
+ it "identifies whether windows? or posix?" do
6
+ if ENV['OS'] == 'Windows_NT'
7
+ unless RUBY_PLATFORM =~ /cygwin/
8
+ assert OS.windows? == true
9
+ assert OS.doze? == true
10
+ assert OS.posix? == false
11
+ else
12
+ assert OS::Underlying.windows?
13
+ assert OS.windows? == false
14
+ assert OS.posix? == true
15
+ end
16
+ assert OS::Underlying.windows?
17
+ elsif [/linux/, /darwin/].any? {|posix_pattern| (RbConfig::CONFIG["host_os"] =~ posix_pattern) || RUBY_PLATFORM =~ posix_pattern }
18
+ assert OS.windows? == false
19
+ assert OS.posix? == true
20
+ assert !OS::Underlying.windows?
21
+ else
22
+ pending "create test"
23
+ end
24
+ end
25
+
26
+ it "has a bits method" do
27
+ if RUBY_PLATFORM =~ /mingw32/
28
+ assert OS.bits == 32
29
+ elsif RUBY_PLATFORM =~ /64/ # linux...
30
+ assert OS.bits == 64
31
+ elsif RUBY_PLATFORM =~ /i686/
32
+ assert OS.bits == 32
33
+ elsif RUBY_PLATFORM =~ /java/ && RbConfig::CONFIG['host_os'] =~ /32$/
34
+ assert OS.bits == 32
35
+ elsif RUBY_PLATFORM =~ /java/ && RbConfig::CONFIG['host_cpu'] =~ /i386/
36
+ assert OS.bits == 32
37
+ elsif RUBY_PLATFORM =~ /i386/
38
+ assert OS.bits == 32
39
+ else
40
+ pending "os bits not tested!" + RUBY_PLATFORM + ' ' + RbConfig::CONFIG['host_os']
41
+ end
42
+
43
+ end
44
+
45
+ it "should have an iron_ruby method" do
46
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ironruby'
47
+ assert OS.iron_ruby? == true
48
+ else
49
+ assert OS.iron_ruby? == false
50
+ end
51
+ end
52
+
53
+ it "should know if you're on java" do
54
+ if RUBY_PLATFORM == 'java'
55
+ assert OS.java? == true # must be [true | false]
56
+ else
57
+ assert OS.java? == false
58
+ end
59
+ end
60
+
61
+ it "should have a ruby_bin method" do
62
+ if OS.windows?
63
+ assert OS.ruby_bin.include?('.exe')
64
+ if OS.iron_ruby?
65
+ assert OS.ruby_bin.include?('ir.exe')
66
+ else
67
+ assert OS.ruby_bin.include?('ruby.exe')
68
+ end
69
+ else
70
+ assert OS.ruby_bin.include?('ruby') && OS.ruby_bin.include?('/')
71
+ end
72
+
73
+ if OS.java?
74
+ assert OS.ruby_bin.include?('jruby') # I think
75
+ end
76
+
77
+ end
78
+
79
+ it "should have a cygwin? method" do
80
+ if RUBY_PLATFORM =~ /cygwin/
81
+ assert OS.cygwin? == true
82
+ else
83
+ assert OS.cygwin? == false
84
+ end
85
+ end
86
+
87
+ it "should have a functional mac? method" do
88
+ if RUBY_PLATFORM =~ /darwin/
89
+ assert OS.mac? == true
90
+ else
91
+ assert OS.mac? == false
92
+ end
93
+ end
94
+
95
+ it "should have a way to get rss_bytes on each platform" do
96
+ bytes = OS.rss_bytes
97
+ assert bytes > 0 # should always be true
98
+ assert bytes.is_a?(Numeric) # don't want strings from any platform...
99
+ end
100
+
101
+ it "should tell you what the right /dev/null is" do
102
+ if OS.windows?
103
+ OS.dev_null.should == "NUL"
104
+ else
105
+ OS.dev_null.should == "/dev/null"
106
+ end
107
+ end
108
+
109
+ it "should have a jruby method" do
110
+ if defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /^(jruby|java)/
111
+ assert OS.jruby?
112
+ else
113
+ assert !OS.jruby?
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+ describe OS, "provides access to to underlying config values" do
120
+
121
+ describe "#config, supplys the CONFIG hash" do
122
+ subject { OS.config }
123
+
124
+ specify { subject.should be_a(Hash) }
125
+
126
+ it "should supply 'host_cpu'" do
127
+ subject['host_cpu'].should eq(RbConfig::CONFIG['host_cpu'])
128
+ end
129
+
130
+ it "should supply 'host_os'" do
131
+ subject['host_os'].should eq(RbConfig::CONFIG['host_os'])
132
+ end
133
+ end
134
+
135
+ describe "by providing a delegate method for relevant keys in RbConfig::CONFIG" do
136
+ %w(host host_cpu host_os).sort.each do |config_key|
137
+ it "should delegate '#{config_key}'" do
138
+ expected = "TEST #{config_key}"
139
+ RbConfig::CONFIG.should_receive(:[]).with(config_key).and_return(expected)
140
+
141
+ OS.send(config_key).should == expected
142
+ end
143
+ end
144
+ end
145
+ end
data/spec/osx_spec.rb ADDED
@@ -0,0 +1,29 @@
1
+ require File.expand_path('spec_helper.rb', File.dirname(__FILE__))
2
+
3
+ describe 'For OSX (Snow Leopard, 10.6),' do
4
+ before(:each) do
5
+ ENV.stub!(:[]).with('OS').and_return(nil)
6
+ # Issues stubbing RUBY_PLATFORM, using RbConfig instead.
7
+ # Kernel.stub!(:RUBY_PLATFORM => "x86_64-darwin10.6")
8
+ RbConfig::CONFIG.stub!(:[]).with('host_os').and_return("darwin10.6.0")
9
+ RbConfig::CONFIG.stub!(:[]).with('host_cpu').and_return('i386')
10
+ end
11
+
12
+ describe OS do
13
+ subject { OS } # class, not instance
14
+
15
+ it { should be_mac }
16
+ it { should be_osx }
17
+ it { should be_posix }
18
+
19
+ it { should_not be_windows }
20
+
21
+ end
22
+
23
+ describe OS::Underlying do
24
+ subject { OS::Underlying } # class, not instance
25
+
26
+ it { should be_bsd }
27
+ it { should_not be_windows }
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
2
+ require File.expand_path('../lib/os.rb', File.dirname(__FILE__))
3
+
4
+ require 'rspec' # rspec2
5
+
6
+ RSpec.configure do |config|
7
+ config.expect_with :rspec, :stdlib # enable `should` OR `assert`
8
+ end
9
+
metadata CHANGED
@@ -1,41 +1,39 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: os
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.7.4
4
+ hash: 63
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
6
11
  platform: ruby
7
12
  authors:
8
- - rdp
9
- - David McCullars
13
+ - rdp
14
+ - David McCullars
10
15
  autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
18
 
14
- date: 2011-02-25 00:00:00 -07:00
19
+ date: 2011-05-19 00:00:00 -06:00
15
20
  default_executable:
16
21
  dependencies:
17
- - !ruby/object:Gem::Dependency
18
- name: rspec
19
- prerelease: false
20
- requirement: &id001 !ruby/object:Gem::Requirement
21
- none: false
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- version: "2.0"
26
- type: :development
27
- version_requirements: *id001
28
- - !ruby/object:Gem::Dependency
29
- name: sane
30
- prerelease: false
31
- requirement: &id002 !ruby/object:Gem::Requirement
32
- none: false
33
- requirements:
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: "0"
37
- type: :development
38
- version_requirements: *id002
22
+ - !ruby/object:Gem::Dependency
23
+ name: rspec
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 2
33
+ - 0
34
+ version: "2.0"
35
+ type: :development
36
+ version_requirements: *id001
39
37
  description: The OS gem allows for some useful and easy functions, like OS.windows? (=> true or false) OS.bits ( => 32 or 64) etc"
40
38
  email: rogerpack2005@gmail.com
41
39
  executables: []
@@ -43,41 +41,59 @@ executables: []
43
41
  extensions: []
44
42
 
45
43
  extra_rdoc_files:
46
- - README.rdoc
44
+ - README.rdoc
47
45
  files:
48
- - .document
49
- - README.rdoc
50
- - Rakefile
51
- - VERSION
52
- - lib/os.rb
53
- - spec/spec.os.rb
46
+ - .autotest
47
+ - .document
48
+ - .gitignore
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - README.rdoc
52
+ - Rakefile
53
+ - VERSION
54
+ - autotest/discover.rb
55
+ - lib/os.rb
56
+ - os.gemspec
57
+ - spec/linux_spec.rb
58
+ - spec/os_spec.rb
59
+ - spec/osx_spec.rb
60
+ - spec/spec_helper.rb
54
61
  has_rdoc: true
55
62
  homepage: http://github.com/rdp/os
56
63
  licenses: []
57
64
 
58
65
  post_install_message:
59
- rdoc_options: []
60
-
66
+ rdoc_options:
67
+ - --charset=UTF-8
61
68
  require_paths:
62
- - lib
69
+ - lib
63
70
  required_ruby_version: !ruby/object:Gem::Requirement
64
71
  none: false
65
72
  requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: "0"
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
69
79
  required_rubygems_version: !ruby/object:Gem::Requirement
70
80
  none: false
71
81
  requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: "0"
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
75
88
  requirements: []
76
89
 
77
90
  rubyforge_project:
78
- rubygems_version: 1.5.1
91
+ rubygems_version: 1.3.7
79
92
  signing_key:
80
93
  specification_version: 3
81
94
  summary: Simple and easy way to know if you're on windows or not (reliably), as well as how many bits the OS is, etc.
82
95
  test_files:
83
- - spec/spec.os.rb
96
+ - spec/linux_spec.rb
97
+ - spec/osx_spec.rb
98
+ - spec/os_spec.rb
99
+ - spec/spec_helper.rb