Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nickhoffman/capistrano in…
Browse files Browse the repository at this point in the history
…to nickhoffman-master
  • Loading branch information
leehambley committed Jan 24, 2011
2 parents 75efaf3 + 5a144cd commit fec72c8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/capistrano/recipes/deploy/remote_dependency.rb
Expand Up @@ -43,6 +43,12 @@ def gem(name, version, options={})
self
end

def deb(name, version, options={})
@message ||= "package `#{name}' #{version} could not be found"
try("dpkg -s #{name} | grep '^Version: #{version}'", options)
self
end

def match(command, expect, options={})
expect = Regexp.new(Regexp.escape(expect.to_s)) unless expect.is_a?(Regexp)

Expand Down
23 changes: 22 additions & 1 deletion test/deploy/remote_dependency_test.rb
Expand Up @@ -37,6 +37,12 @@ def test_should_use_standard_error_message_for_gem
assert_equal "gem `capistrano' 9.9 could not be found (host)", @dependency.message
end

def test_should_use_standard_error_message_for_deb
setup_for_a_configuration_deb_run("dpkg", "1.15", false)
@dependency.deb("dpkg", "1.15")
assert_equal "package `dpkg' 1.15 could not be found (host)", @dependency.message
end

def test_should_fail_if_directory_not_found
setup_for_a_configuration_run("test -d /data", false)
assert !@dependency.directory("/data").pass?
Expand All @@ -52,7 +58,7 @@ def test_should_fail_if_file_not_found
assert !@dependency.file("/data/foo.txt").pass?
end

def test_should_pas_if_file_found
def test_should_pass_if_file_found
setup_for_a_configuration_run("test -f /data/foo.txt", true)
assert @dependency.file("/data/foo.txt").pass?
end
Expand Down Expand Up @@ -87,6 +93,16 @@ def test_should_pass_if_gem_found
assert @dependency.gem("capistrano", 9.9).pass?
end

def test_should_pass_if_deb_found
setup_for_a_configuration_deb_run("dpkg", "1.15", true)
assert @dependency.deb("dpkg", "1.15").pass?
end

def test_should_fail_if_deb_not_found
setup_for_a_configuration_deb_run("dpkg", "1.15", false)
assert !@dependency.deb("dpkg", "1.15").pass?
end

def test_should_use_alternative_message_if_provided
setup_for_a_configuration_run("which cat", false)
@dependency.command("cat").or("Sorry")
Expand All @@ -111,4 +127,9 @@ def setup_for_a_configuration_gem_run(name, version, passing)
find_gem_cmd = "gem specification --version '#{version}' #{name} 2>&1 | awk 'BEGIN { s = 0 } /^name:/ { s = 1; exit }; END { if(s == 0) exit 1 }'"
setup_for_a_configuration_run(find_gem_cmd, passing)
end

def setup_for_a_configuration_deb_run(name, version, passing)
find_deb_cmd = "dpkg -s #{name} | grep '^Version: #{version}'"
setup_for_a_configuration_run(find_deb_cmd, passing)
end
end

0 comments on commit fec72c8

Please sign in to comment.