Permalink
Browse files

add some tests for the perforce.rb scm private method

  • Loading branch information...
1 parent 6b7cf10 commit cc0f601f86dd056aed18f6afa9369006c83beac6 @ak47 ak47 committed Aug 25, 2011
Showing with 32 additions and 1 deletion.
  1. +9 −1 lib/capistrano/recipes/deploy/scm/perforce.rb
  2. +23 −0 test/deploy/scm/perforce_test.rb
@@ -122,7 +122,15 @@ def p4client_root
end
def rev_no(revision)
- return "@#{variable(:p4_label)}" if variable(:p4_label)
+ if variable(:p4_label)
+ p4_label = if variable(:p4_label) =~ /\A@/
+ variable(:p4_label)
+ else
+ "@#{variable(:p4_label)}"
+ end
+ return p4_label
+ end
+
case revision.to_s
when "head"
"#head"
@@ -0,0 +1,23 @@
+require "utils"
+require 'capistrano/recipes/deploy/scm/perforce'
+
+class DeploySCMPerforceTest < Test::Unit::TestCase
+ class TestSCM < Capistrano::Deploy::SCM::Perforce
+ default_command "perforce"
+ end
+ def setup
+ @config = { :repository => "." }
+ @source = TestSCM.new(@config)
+ end
+
+ def test_p4_label
+ @config[:p4_label] = "some_p4_label"
+ assert_equal "@some_p4_label", @source.send(:rev_no, 'foo')
+ end
+
+ def test_p4_label_with_symbol
+ @config[:p4_label] = "@some_p4_label"
+ assert_equal "@some_p4_label", @source.send(:rev_no, 'foo')
+ end
+
+end

0 comments on commit cc0f601

Please sign in to comment.