diff --git a/padrino-performance/lib/padrino-performance/os.rb b/padrino-performance/lib/padrino-performance/os.rb index cbba69012..3829b11e6 100644 --- a/padrino-performance/lib/padrino-performance/os.rb +++ b/padrino-performance/lib/padrino-performance/os.rb @@ -4,11 +4,11 @@ module Performance # Source: http://stackoverflow.com/questions/170956/how-can-i-find-which-operating-system-my-ruby-program-is-running-on module OS def self.windows? - (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil + (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RbConfig::CONFIG['target_os']) != nil end def self.mac? - (/darwin/ =~ RUBY_PLATFORM) != nil + (/darwin/ =~ RbConfig::CONFIG['target_os']) != nil end def self.unix? diff --git a/padrino-performance/test/helper.rb b/padrino-performance/test/helper.rb new file mode 100644 index 000000000..2e6d9aa59 --- /dev/null +++ b/padrino-performance/test/helper.rb @@ -0,0 +1,12 @@ +require File.expand_path('../../../load_paths', __FILE__) +require File.join(File.dirname(__FILE__), '..', '..', 'padrino-core', 'test', 'mini_shoulda') + +require 'padrino-core' +require 'padrino-performance' +require 'rack' +require 'rack/test' + +class MiniTest::Spec + include Rack::Test::Methods +end + diff --git a/padrino-performance/test/test_os.rb b/padrino-performance/test/test_os.rb new file mode 100644 index 000000000..89bdb5a7f --- /dev/null +++ b/padrino-performance/test/test_os.rb @@ -0,0 +1,61 @@ +require File.expand_path(File.dirname(__FILE__) + '/helper') + +describe "Padrino Performance OS Module" do + WINDOWS_RELATED_SYSTEMS = %w(cygwin mswin mingw bccwin wince emx) + + context "#windows?" do + should "return false if OS is now windows" do + RbConfig::CONFIG['target_os'] = "linux" + refute(Padrino::Performance::OS.windows?, "No non windows system given") + end + + should "return true if we have some windows instance" do + WINDOWS_RELATED_SYSTEMS.each do |system| + RbConfig::CONFIG['target_os'] = system + assert(Padrino::Performance::OS.windows?, "#{system} is no windows related operation system.") + end + end + end + + context "#mac?" do + should "return true if we have darwin running" do + RbConfig::CONFIG['target_os'] = 'darwin' + assert(Padrino::Performance::OS.mac?, "We have no Mac related system running") + end + + should "return false if we have linux running" do + RbConfig::CONFIG['target_os'] = 'linux' + refute(Padrino::Performance::OS.mac?, "We have no Mac related system running") + end + end + + context "#unix?" do + should "return true if OS is not windows" do + RbConfig::CONFIG['target_os'] = 'linux' + assert(Padrino::Performance::OS.unix?, "We have no windows related system running") + end + + should "return false if OS is windows" do + WINDOWS_RELATED_SYSTEMS.each do |system| + RbConfig::CONFIG['target_os'] = system + refute(Padrino::Performance::OS.unix?, "#{system} is windows related operation system.") + end + end + end + + context "#linux?" do + should "return true if we have no Windows or Mac related OS" do + RbConfig::CONFIG['target_os'] = 'linux' + assert(Padrino::Performance::OS.linux?, 'We have either Mac or Windows operation system.') + end + + should "return false if we have a Windows or Mac related OS" do + RbConfig::CONFIG['target_os'] = 'mingw' + refute(Padrino::Performance::OS.linux?, 'We a Windows related operation system.') + + RbConfig::CONFIG['target_os'] = 'darwin' + refute(Padrino::Performance::OS.linux?, 'We a darwin operation system.') + end + end + +end diff --git a/padrino-performance/test/test_padrino_performance.rb b/padrino-performance/test/test_padrino_performance.rb new file mode 100644 index 000000000..711eaa860 --- /dev/null +++ b/padrino-performance/test/test_padrino_performance.rb @@ -0,0 +1,5 @@ +require File.expand_path(File.dirname(__FILE__) + '/helper') + +describe "Padrino Performance" do + +end