public
Description: Piston is a utility that eases vendor branch management. This repository is a complete reimplementation of Piston to provide different backends, depending on the repositories and working copies you pistonize from.
Homepage: http://piston.rubyforge.org/
Clone URL: git://github.com/francois/piston.git
francois (author)
Fri May 09 07:30:21 -0700 2008
commit  50744c398a3e686abd5eb743a5e59ed67929c4ff
tree    bb103c21783ea1be2d799be187c7bbdadc7602a3
parent  1f33caa0eb2ab49783bcba64423255085f3b4c34
piston / test / unit / test_repository.rb
100644 72 lines (57 sloc) 2.508 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require File.dirname(__FILE__) + "/../test_helper"
 
class TestRepository < Test::Unit::TestCase
  def setup
    Piston::Repository.class_variable_set(:@@handlers, [Piston::Git::Repository, Piston::Svn::Repository])
    @repository = Piston::Repository.new("url")
  end
 
  def test_guess_asks_each_handler_in_turn
    Piston::Repository.send(:handlers).clear
    Piston::Repository.add_handler(handler = mock("handler"))
    handler.expects(:understands_url?).with("http://a.repos.com/trunk").returns(false)
    assert_raise Piston::Repository::UnhandledUrl do
      Piston::Repository.guess("http://a.repos.com/trunk")
    end
  end
 
  def test_guess_returns_first_handler_that_understands_the_url
    Piston::Repository.send(:handlers).clear
    url = "svn://a.repos.com/projects/libcalc/trunk"
 
    handler = mock("handler")
    handler.expects(:understands_url?).with(url).returns(true)
    handler_instance = mock("handler_instance")
    handler.expects(:new).with(url).returns(handler_instance)
 
    Piston::Repository.add_handler handler
    assert_equal handler_instance, Piston::Repository.guess(url)
  end
 
  def test_if_guess_return_GIT_repository_when_url_is_git_repository
    assert_equal Piston::Git::Repository.new("git://github.com/francois/piston.git"), Piston::Repository.guess("git://github.com/francois/piston.git")
  end
 
  def test_if_guess_return_SVN_repository_when_url_is_svn_repository
    assert_equal Piston::Svn::Repository.new("svn://svn.com/francois/piston.git"), Piston::Repository.guess("svn://svn.com/francois/piston.git")
  end
 
  def test_guess_when_unhandled_url
    assert_raise(Piston::Repository::UnhandledUrl) { Piston::Repository.guess("invalid") }
  end
 
  def test_handlers
    assert_equal [Piston::Git::Repository, Piston::Svn::Repository], Piston::Repository.handlers
  end
 
  def test_add_handler
    before_add = Piston::Repository.class_variable_get(:@@handlers)
    after_add = before_add << Piston::Git::Repository
    Piston::Repository.add_handler(Piston::Git::Repository)
    assert_equal after_add, Piston::Repository.class_variable_get(:@@handlers)
  end
 
  def test_initialize
    assert_equal "url", @repository.instance_variable_get(:@url)
  end
 
  def test_url
    assert_equal "url", @repository.url
  end
 
  def test_at
    revision = @repository.at("2")
    assert_equal @repository, revision.repository
    assert_equal "2", revision.revision
  end
 
  def test_to_s
    assert_equal "Piston::Repository(url)", @repository.to_s
  end
end