Created
August 2, 2009 19:08
-
-
Save technicalpickles/160156 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run | |
command = "gem install #{gemspec_helper.gem_path}" | |
output.puts "Executing #{command.inspect}:" | |
sh sudo_wrapper(command) # TODO where does sh actually come from!? - rake, apparently | |
end | |
def sudo_wrapper(command) | |
if use_sudo? | |
"sudo #{command}" | |
else | |
command | |
end | |
end | |
def use_sudo? | |
if host_os =~ /mswin|windows|cygwin/i | |
false | |
else | |
true | |
end | |
end | |
def host_os | |
Config::CONFIG['host_os'] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rubyforge_command_context "running" do | |
setup do | |
stub(@gemspec_helper).gem_path { 'pkg/zomg-1.1.1.gem' } | |
stub(@command).sudo_wrapper { 'sudo gem install pkg/zomg-1.1.1.gem' } | |
stub(@command).sh | |
@command.run | |
end | |
should "call sudo wrapper with gem install" do | |
assert_received(@command) {|command| command.sudo_wrapper('gem install pkg/zomg-1.1.1.gem') } | |
end | |
should "call sh with output of sudo wrapper" do | |
assert_received(@command) {|command| command.sh 'sudo gem install pkg/zomg-1.1.1.gem' } | |
end | |
end | |
rubyforge_command_context "use_sudo?" do | |
should "be false on mswin" do | |
stub(@command).host_os { "i386-mswin32" } | |
assert ! @command.use_sudo? | |
end | |
should "be false on windows" do | |
stub(@command).host_os { "windows" } | |
assert ! @command.use_sudo? | |
end | |
should "be false on cygwin" do | |
stub(@command).host_os { "cygwin" } | |
assert ! @command.use_sudo? | |
end | |
should "be true on basically anything else" do | |
stub(@command).host_os { "darwin9" } | |
assert @command.use_sudo? | |
end | |
end | |
rubyforge_command_context "sudo_wrapper" do | |
should "prefix sudo if needed" do | |
stub(@command).use_sudo? { true } | |
assert_equal "sudo blarg", @command.sudo_wrapper("blarg") | |
end | |
should "not prefix with sudo if unneeded" do | |
stub(@command).use_sudo? { false } | |
assert_equal "blarg", @command.sudo_wrapper("blarg") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment