Permalink
Browse files

Abstract windows detection a little in the tests

  • Loading branch information...
1 parent 73c2cb3 commit 4df65929c14ef62d04b5a1ac3129df1221e0f635 @jyurek jyurek committed Aug 17, 2011
Showing with 31 additions and 9 deletions.
  1. +15 −9 spec/cocaine/command_line_spec.rb
  2. +2 −0 spec/spec_helper.rb
  3. +14 −0 spec/support/stub_os.rb
View
24 spec/cocaine/command_line_spec.rb
@@ -28,6 +28,7 @@
end
it "can interpolate quoted variables into the parameters" do
+ on_unix!
cmd = Cocaine::CommandLine.new("convert",
":one :{two}",
:one => "a.jpg",
@@ -37,7 +38,7 @@
end
it "quotes command line options differently if we're on windows" do
- Cocaine::CommandLine.stubs(:unix?).returns(false)
+ on_windows!
cmd = Cocaine::CommandLine.new("convert",
":one :{two}",
:one => "a.jpg",
@@ -56,7 +57,7 @@
end
it "can quote and interpolate dangerous variables even on windows" do
- Cocaine::CommandLine.stubs(:unix?).returns(false)
+ on_windows!
cmd = Cocaine::CommandLine.new("convert",
":one :two",
:one => "`rm -rf`.jpg",
@@ -80,7 +81,7 @@
end
it "adds redirection to get rid of stderr in cmd.exe" do
- Cocaine::CommandLine.stubs(:unix?).returns(false)
+ on_windows!
cmd = Cocaine::CommandLine.new("convert",
"a.jpg b.png",
:swallow_stderr => true)
@@ -130,13 +131,18 @@
end
end
- 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
+ it "detects that the system is unix" do
+ on_unix!
+ Cocaine::CommandLine.unix?.should be_true
+ end
+
+ it "detects that the system is windows" do
+ on_windows!
+ Cocaine::CommandLine.unix?.should be_false
end
- 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
+ it "detects that the system is windows (mingw)" do
+ on_windows!("mingw")
@mike-burns
mike-burns Aug 17, 2011

I'd rather see this as on_mingw!.

+ Cocaine::CommandLine.unix?.should be_false
end
end
View
2 spec/spec_helper.rb
@@ -1,10 +1,12 @@
require 'rspec'
require './spec/support/with_exitstatus'
+require './spec/support/stub_os'
require 'mocha'
require 'bourne'
require 'cocaine'
RSpec.configure do |config|
config.mock_with :mocha
config.include WithExitstatus
+ config.include StubOS
end
View
14 spec/support/stub_os.rb
@@ -0,0 +1,14 @@
+module StubOS
+ def on_windows!(host_string = 'mswin')
+ stub_os(host_string)
+ end
+
+ def on_unix!(host_string = 'darwin11.0.0')
+ stub_os(host_string)
@mike-burns
mike-burns Aug 17, 2011

Why does this take an argument?

+ end
+
+ def stub_os(host_string)
+ # http://blog.emptyway.com/2009/11/03/proper-way-to-detect-windows-platform-in-ruby/
+ Config::CONFIG.stubs(:[]).with('host_os').returns(host_string)
+ end
+end

0 comments on commit 4df6592

Please sign in to comment.