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
piston / test / unit / test_lock_unlock.rb
100644 48 lines (41 sloc) 1.346 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
require File.dirname(__FILE__) + "/../test_helper"
 
class TestLockUnlock < Test::Unit::TestCase
  def setup
    @values = {:lock => "false", "handler" => { :repository => "repository" }}
    @wc = mock("WorkingCopy")
  end
  
  def test_run
    run_and_verify 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, @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
    yield
    piston_lock.run(true)
  end
 
  def piston_lock
    Piston::WorkingCopy.expects(:guess).with("directory").returns(@wc)
    Piston::Commands::LockUnlock.new(:wcdir => "directory", :verbose => "verbose",
                                     :quiet => "quiet", :force => "force")
  end
end