Mercurial > hg > soundsoftware-site
comparison test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb @ 118:b859cc0c4fa1 cannam
Merge from branch "redmine-1.1"
author | Chris Cannam |
---|---|
date | Thu, 13 Jan 2011 13:21:03 +0000 |
parents | af80e5618e9b |
children | cd2282d2aa55 |
comparison
equal
deleted
inserted
replaced
114:8a205cc048de | 118:b859cc0c4fa1 |
---|---|
1 require File.dirname(__FILE__) + '/../../../../../test_helper' | 1 require File.expand_path('../../../../../../test_helper', __FILE__) |
2 begin | 2 begin |
3 require 'mocha' | 3 require 'mocha' |
4 | 4 |
5 class MercurialAdapterTest < ActiveSupport::TestCase | 5 class MercurialAdapterTest < ActiveSupport::TestCase |
6 | 6 |
7 TEMPLATES_DIR = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATES_DIR | 7 TEMPLATES_DIR = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATES_DIR |
8 TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME | 8 TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME |
9 TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION | 9 TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION |
10 | 10 |
11 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' | 11 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' |
12 | 12 |
13 def test_hgversion | 13 if File.directory?(REPOSITORY_PATH) |
14 to_test = { "0.9.5" => [0,9,5], | 14 def setup |
15 "1.0" => [1,0], | 15 @adapter = Redmine::Scm::Adapters::MercurialAdapter.new(REPOSITORY_PATH) |
16 "1e4ddc9ac9f7+20080325" => nil, | |
17 "1.0.1+20080525" => [1,0,1], | |
18 "1916e629a29d" => nil} | |
19 | |
20 to_test.each do |s, v| | |
21 test_hgversion_for(s, v) | |
22 end | 16 end |
23 end | 17 |
24 | 18 def test_hgversion |
25 def test_template_path | 19 to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], |
26 to_test = { [0,9,5] => "0.9.5", | 20 "Mercurial Distributed SCM (1.0)\n" => [1,0], |
27 [1,0] => "1.0", | 21 "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil, |
28 [] => "1.0", | 22 "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1], |
29 [1,0,1] => "1.0"} | 23 "Mercurial Distributed SCM (1916e629a29d)\n" => nil, |
30 | 24 "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5], |
31 to_test.each do |v, template| | 25 "(1.6)\n(1.7)\n(1.8)" => [1,6], |
32 test_template_path_for(v, template) | 26 "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]} |
27 | |
28 to_test.each do |s, v| | |
29 test_hgversion_for(s, v) | |
30 end | |
33 end | 31 end |
34 end | 32 |
35 | 33 def test_template_path |
36 private | 34 to_test = { [0,9,5] => "0.9.5", |
37 | 35 [1,0] => "1.0", |
38 def test_hgversion_for(hgversion, version) | 36 [] => "1.0", |
39 Redmine::Scm::Adapters::MercurialAdapter.expects(:hgversion_from_command_line).returns(hgversion) | 37 [1,0,1] => "1.0", |
40 adapter = Redmine::Scm::Adapters::MercurialAdapter | 38 [1,7] => "1.0", |
41 assert_equal version, adapter.hgversion | 39 [1,7,1] => "1.0" } |
42 end | 40 to_test.each do |v, template| |
43 | 41 test_template_path_for(v, template) |
44 def test_template_path_for(version, template) | 42 end |
45 adapter = Redmine::Scm::Adapters::MercurialAdapter | 43 end |
46 assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", adapter.template_path_for(version) | 44 |
47 assert File.exist?(adapter.template_path_for(version)) | 45 def test_cat |
46 assert @adapter.cat("sources/welcome_controller.rb", 2) | |
47 assert_nil @adapter.cat("sources/welcome_controller.rb") | |
48 end | |
49 | |
50 private | |
51 | |
52 def test_hgversion_for(hgversion, version) | |
53 @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) | |
54 assert_equal version, @adapter.class.hgversion | |
55 end | |
56 | |
57 def test_template_path_for(version, template) | |
58 assert_equal "#{TEMPLATES_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", | |
59 @adapter.class.template_path_for(version) | |
60 assert File.exist?(@adapter.class.template_path_for(version)) | |
61 end | |
62 else | |
63 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" | |
64 def test_fake; assert true end | |
48 end | 65 end |
49 end | 66 end |
50 | 67 |
51 rescue LoadError | 68 rescue LoadError |
52 def test_fake; assert(false, "Requires mocha to run those tests") end | 69 class MercurialMochaFake < ActiveSupport::TestCase |
70 def test_fake; assert(false, "Requires mocha to run those tests") end | |
71 end | |
53 end | 72 end |
73 |