jamis / capistrano

Remote multi-server automation tool. This repository is no longer being actively maintained. Please ask on the mailing list to find someone who has a well-maintained fork. Thanks!

This URL has Read+Write access

jamis (author)
Fri Feb 13 19:05:25 -0800 2009
commit  2ce539d87c928f41d82f7bfda84e228d3948d82b
tree    7b5964513a8a02c39f1dfd2216ec8b053926007a
parent  42ff8b9e7dd9ec1c1de59b8f7dc0c0461cc2741b
capistrano / test / extensions_test.rb
100644 69 lines (57 sloc) 2.476 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
require "utils"
require 'capistrano'
 
class ExtensionsTest < Test::Unit::TestCase
  module CustomExtension
    def do_something(command)
      run(command)
    end
  end
 
  def setup
    @config = Capistrano::Configuration.new
  end
 
  def teardown
    Capistrano::EXTENSIONS.keys.each { |e| Capistrano.remove_plugin(e) }
  end
 
  def test_register_plugin_should_add_instance_method_on_configuration_and_return_true
    assert !@config.respond_to?(:custom_stuff)
    assert Capistrano.plugin(:custom_stuff, CustomExtension)
    assert @config.respond_to?(:custom_stuff)
  end
 
  def test_register_plugin_that_already_exists_should_return_false
    assert Capistrano.plugin(:custom_stuff, CustomExtension)
    assert !Capistrano.plugin(:custom_stuff, CustomExtension)
  end
 
  def test_register_plugin_with_public_method_name_should_fail
    method = Capistrano::Configuration.public_instance_methods.first
    assert_not_nil method, "need a public instance method for testing"
    assert_raises(Capistrano::Error) { Capistrano.plugin(method, CustomExtension) }
  end
 
  def test_register_plugin_with_protected_method_name_should_fail
    method = Capistrano::Configuration.protected_instance_methods.first
    assert_not_nil method, "need a protected instance method for testing"
    assert_raises(Capistrano::Error) { Capistrano.plugin(method, CustomExtension) }
  end
 
  def test_register_plugin_with_private_method_name_should_fail
    method = Capistrano::Configuration.private_instance_methods.first
    assert_not_nil method, "need a private instance method for testing"
    assert_raises(Capistrano::Error) { Capistrano.plugin(method, CustomExtension) }
  end
 
  def test_unregister_plugin_that_does_not_exist_should_return_false
    assert !Capistrano.remove_plugin(:custom_stuff)
  end
 
  def test_unregister_plugin_should_remove_method_and_return_true
    assert Capistrano.plugin(:custom_stuff, CustomExtension)
    assert @config.respond_to?(:custom_stuff)
    assert Capistrano.remove_plugin(:custom_stuff)
    assert !@config.respond_to?(:custom_stuff)
  end
 
  def test_registered_plugin_proxy_should_return_proxy_object
    Capistrano.plugin(:custom_stuff, CustomExtension)
    assert_instance_of Capistrano::ExtensionProxy, @config.custom_stuff
  end
 
  def test_proxy_object_should_delegate_to_configuration
    Capistrano.plugin(:custom_stuff, CustomExtension)
    @config.expects(:run).with("hello")
    @config.custom_stuff.do_something("hello")
  end
end