Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/branches/cap2-on-netssh2/test/configuration_test.rb

Revision 6461, 2.5 kB (checked in by minam, 2 years ago)

before/after hooks for a namespace's default task can be named after the namespace, instead of "before_default", etc.

Line 
1 require "#{File.dirname(__FILE__)}/utils"
2 require 'capistrano/configuration'
3
4 # These tests are only for testing the integration of the various components
5 # of the Configuration class. To test specific features, please look at the
6 # tests under test/configuration.
7
8 class ConfigurationTest < Test::Unit::TestCase
9   def setup
10     @config = Capistrano::Configuration.new
11   end
12
13   def test_connections_execution_loading_namespaces_roles_and_variables_modules_should_integrate_correctly
14     Capistrano::SSH.expects(:connect).with { |s,c| s.host == "www.capistrano.test" && c == @config }.returns(:session)
15     Capistrano::Command.expects(:process).with("echo 'hello world'", [:session], :logger => @config.logger)
16
17     @config.load do
18       role :test, "www.capistrano.test"
19       set  :message, "hello world"
20       namespace :testing do
21         task :example, :roles => :test do
22           run "echo '#{message}'"
23         end
24       end
25     end
26
27     @config.testing.example
28   end
29
30   def test_tasks_in_nested_namespace_should_be_able_to_call_tasks_in_same_namespace
31     @config.namespace(:outer) do
32       task(:first) { set :called_first, true }
33       namespace(:inner) do
34         task(:first) { set :called_inner_first, true }
35         task(:second) { first }
36       end
37     end
38
39     @config.outer.inner.second
40     assert !@config[:called_first]
41     assert @config[:called_inner_first]
42   end
43
44   def test_tasks_in_nested_namespace_should_be_able_to_call_tasks_in_parent_namespace
45     @config.namespace(:outer) do
46       task(:first) { set :called_first, true }
47       namespace(:inner) do
48         task(:second) { first }
49       end
50     end
51
52     @config.outer.inner.second
53     assert @config[:called_first]
54   end
55
56   def test_tasks_in_nested_namespace_should_be_able_to_call_shadowed_tasks_in_parent_namespace
57     @config.namespace(:outer) do
58       task(:first) { set :called_first, true }
59       namespace(:inner) do
60         task(:first) { set :called_inner_first, true }
61         task(:second) { parent.first }
62       end
63     end
64
65     @config.outer.inner.second
66     assert @config[:called_first]
67     assert !@config[:called_inner_first]
68   end
69
70   def test_hooks_for_default_task_should_be_found_if_named_after_the_namespace
71     @config.namespace(:outer) do
72       task(:default) { set :called_default, true }
73       task(:before_outer) { set :called_before_outer, true }
74       task(:after_outer) { set :called_after_outer, true }
75     end
76     @config.outer.default
77     assert @config[:called_before_outer]
78     assert @config[:called_default]
79     assert @config[:called_after_outer]
80   end
81 end
Note: See TracBrowser for help on using the browser.