Skip to content
This repository has been archived by the owner on Feb 7, 2018. It is now read-only.

Commit

Permalink
Use RbConfig to detect platform (fixes #2). Thanks, @alextk
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Aug 12, 2011
1 parent f2181af commit 73c2cb3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/cocaine.rb
@@ -1,3 +1,4 @@
require 'rbconfig'
require 'cocaine/command_line'
require 'cocaine/exceptions'

Expand Down
2 changes: 1 addition & 1 deletion lib/cocaine/command_line.rb
Expand Up @@ -89,7 +89,7 @@ def bit_bucket
end

def self.unix?
File.exist?("/dev/null")
(Config::CONFIG['host_os'] =~ /mswin|mingw/).nil?
end
end
end
18 changes: 9 additions & 9 deletions spec/cocaine/command_line_spec.rb
Expand Up @@ -3,7 +3,7 @@
describe Cocaine::CommandLine do
before do
Cocaine::CommandLine.path = nil
File.stubs(:exist?).with("/dev/null").returns(true)
Config::CONFIG.stubs(:[]).with('host_os').returns('darwin')
end

it "takes a command and parameters and produce a shell command for bash" do
Expand Down Expand Up @@ -37,7 +37,7 @@
end

it "quotes command line options differently if we're on windows" do
File.stubs(:exist?).with("/dev/null").returns(false)
Cocaine::CommandLine.stubs(:unix?).returns(false)
cmd = Cocaine::CommandLine.new("convert",
":one :{two}",
:one => "a.jpg",
Expand All @@ -56,7 +56,7 @@
end

it "can quote and interpolate dangerous variables even on windows" do
File.stubs(:exist?).with("/dev/null").returns(false)
Cocaine::CommandLine.stubs(:unix?).returns(false)
cmd = Cocaine::CommandLine.new("convert",
":one :two",
:one => "`rm -rf`.jpg",
Expand All @@ -71,7 +71,7 @@
end

it "adds redirection to get rid of stderr in bash" do
File.stubs(:exist?).with("/dev/null").returns(true)
Cocaine::CommandLine.stubs(:unix?).returns(true)
cmd = Cocaine::CommandLine.new("convert",
"a.jpg b.png",
:swallow_stderr => true)
Expand All @@ -80,7 +80,7 @@
end

it "adds redirection to get rid of stderr in cmd.exe" do
File.stubs(:exist?).with("/dev/null").returns(false)
Cocaine::CommandLine.stubs(:unix?).returns(false)
cmd = Cocaine::CommandLine.new("convert",
"a.jpg b.png",
:swallow_stderr => true)
Expand Down Expand Up @@ -130,13 +130,13 @@
end
end

it "detects that the system is unix or windows based on presence of /dev/null" do
File.stubs(:exist?).returns(true)
it "detects that the system is unix or windows based on RbConfig" do
Config::CONFIG.stubs(:[]).with('host_os').returns('darwin')
Cocaine::CommandLine.unix?.should == true
end

it "detects that the system is not unix or windows based on absence of /dev/null" do
File.stubs(:exist?).returns(false)
it "detects that the system is not unix or windows based on RbConfig" do
Config::CONFIG.stubs(:[]).with('host_os').returns('mswin')
Cocaine::CommandLine.unix?.should_not == true
end
end

0 comments on commit 73c2cb3

Please sign in to comment.