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
Search Repo:
piston / test / unit / test_lock_unlock.rb
100644 58 lines (51 sloc) 1.693 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
require File.dirname(__FILE__) + "/../test_helper"
 
class TestLockUnlock < Test::Unit::TestCase
  def setup
    @values = {"lock" => false}
    @wcdir = "tmp/wcdir"
    @wc = mock("WorkingCopy")
  end
  
  def test_lock_working_copy
    run_and_verify(true) do
      @wc.expects(:exist?).returns(true)
      @wc.expects(:pistonized?).returns(true)
      @wc.expects(:recall).returns(@values)
      @wc.expects(:finalize).returns(@values)
      @wc.expects(:remember).with(@values.merge("lock" => true), @values["handler"]).returns(@values)
    end
  end
 
  def test_unlock_working_copy
    run_and_verify(false) do
      @wc.expects(:exist?).returns(true)
      @wc.expects(:pistonized?).returns(true)
      @wc.expects(:recall).returns(@values)
      @wc.expects(:finalize).returns(@values)
      @wc.expects(:remember).with(@values.merge("lock" => false), @values["handler"]).returns(@values)
    end
  end
  
  def test_run_when_directory_not_exist
    assert_raise(Piston::WorkingCopy::NotWorkingCopy) do
      run_and_verify do
        @wc.expects(:exist?).returns(false)
      end
    end
  end
  
  def test_run_when_directory_exist_but_yml_not_exit
    assert_raise(Piston::WorkingCopy::NotWorkingCopy) do
      run_and_verify do
        @wc.expects(:exist?).returns(true)
        @wc.expects(:pistonized?).returns(false)
      end
    end
  end
 
  private
  def run_and_verify(lock=true)
    yield
    lock_unlock_command.run(@wcdir, lock)
  end
 
  def lock_unlock_command
    Piston::WorkingCopy.expects(:guess).with(@wcdir).returns(@wc)
    Piston::Commands::LockUnlock.new(:verbose => "verbose",
                                     :quiet => "quiet", :force => "force")
  end
end