cap-util 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -2
- data/Gemfile +3 -3
- data/{LICENSE → LICENSE.txt} +1 -1
- data/README.md +15 -15
- data/Rakefile +0 -7
- data/cap-util.gemspec +11 -9
- data/lib/cap-util.rb +2 -2
- data/lib/cap-util/server_roles.rb +3 -3
- data/lib/cap-util/timer.rb +1 -1
- data/lib/cap-util/unset_var.rb +2 -0
- data/lib/cap-util/version.rb +1 -1
- data/test/helper.rb +8 -17
- data/test/support/an_cap_util.rb +14 -0
- data/test/{cap_util_tests.rb → system/cap_util_tests.rb} +3 -2
- data/test/{fake_cap_tests.rb → unit/fake_cap_tests.rb} +3 -4
- data/test/{git_branch_tests.rb → unit/git_branch_tests.rb} +3 -4
- data/test/{local_cmd_runner_tests.rb → unit/local_cmd_runner_tests.rb} +3 -4
- data/test/{rake_task_tests.rb → unit/rake_task_tests.rb} +7 -8
- data/test/unit/server_roles_tests.rb +115 -0
- data/test/{server_roles_yaml_tests.rb → unit/server_roles_yaml_tests.rb} +4 -5
- data/test/{shared_path_tests.rb → unit/shared_path_tests.rb} +4 -5
- data/test/{timer_tests.rb → unit/timer_tests.rb} +4 -5
- data/test/{unset_var_tests.rb → unit/unset_var_tests.rb} +3 -4
- metadata +45 -45
- data/test/irb.rb +0 -9
- data/test/server_roles_tests.rb +0 -120
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/{LICENSE → LICENSE.txt}
RENAMED
data/README.md
CHANGED
@@ -2,23 +2,9 @@
|
|
2
2
|
|
3
3
|
A set of utilities for writing cap tasks. Use these to help extract business logic from your tasks and test them.
|
4
4
|
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'cap-util'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install cap-util
|
18
|
-
|
19
5
|
## The Mixin
|
20
6
|
|
21
|
-
The main `CapUtil` mixin can be used to make any class a cap utility. All the cap util requires is that your class define a `cap` method that returns an instance of a cap invocations.
|
7
|
+
The main `CapUtil` mixin can be used to make any class a cap utility. All the cap util requires is that your class define a `cap` method that returns an instance of a cap invocations. The mixin provides a default `attr_accessor :cap` for you; set an `@cap` instance variable to use it or override it with a custom `def cap` method.
|
22
8
|
|
23
9
|
```ruby
|
24
10
|
# in some_great_util.rb
|
@@ -166,6 +152,20 @@ class MyServerRolesYaml < CapUtil::ServerRolesYaml
|
|
166
152
|
end
|
167
153
|
```
|
168
154
|
|
155
|
+
## Installation
|
156
|
+
|
157
|
+
Add this line to your application's Gemfile:
|
158
|
+
|
159
|
+
gem 'cap-util'
|
160
|
+
|
161
|
+
And then execute:
|
162
|
+
|
163
|
+
$ bundle
|
164
|
+
|
165
|
+
Or install it yourself as:
|
166
|
+
|
167
|
+
$ gem install cap-util
|
168
|
+
|
169
169
|
## Contributing
|
170
170
|
|
171
171
|
1. Fork it
|
data/Rakefile
CHANGED
data/cap-util.gemspec
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "cap-util/version"
|
3
5
|
|
4
6
|
Gem::Specification.new do |gem|
|
5
7
|
gem.name = "cap-util"
|
6
8
|
gem.version = CapUtil::VERSION
|
7
|
-
gem.description = %q{A set of utilities for writing cap tasks.}
|
8
|
-
gem.summary = %q{A set of utilities for writing cap tasks.}
|
9
|
-
|
10
9
|
gem.authors = ["Kelly Redding", "Collin Redding"]
|
11
10
|
gem.email = ["kelly@kellyredding.com", "collin.redding@me.com"]
|
11
|
+
gem.description = %q{A set of utilities for writing cap tasks.}
|
12
|
+
gem.summary = %q{A set of utilities for writing cap tasks.}
|
12
13
|
gem.homepage = "http://github.com/redding/cap-util"
|
13
14
|
|
14
|
-
gem.files = `git ls-files`.split(
|
15
|
-
gem.
|
16
|
-
gem.
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
18
|
gem.require_paths = ["lib"]
|
18
19
|
|
19
|
-
gem.add_development_dependency("assert", ["~>
|
20
|
+
gem.add_development_dependency("assert", ["~> 2.0"])
|
21
|
+
|
22
|
+
gem.add_dependency("scmd", ["~> 2.0"])
|
20
23
|
gem.add_dependency("capistrano")
|
21
|
-
gem.add_dependency("scmd", ["~>2.0"])
|
22
24
|
|
23
25
|
end
|
data/lib/cap-util.rb
CHANGED
@@ -61,8 +61,8 @@ module CapUtil
|
|
61
61
|
|
62
62
|
attr_reader :hostname, :options
|
63
63
|
|
64
|
-
def initialize(
|
65
|
-
@hostname =
|
64
|
+
def initialize(hostname, options_list=nil)
|
65
|
+
@hostname = hostname
|
66
66
|
@options = {}
|
67
67
|
|
68
68
|
# so, weird cap bug. options have to match type when using them in
|
@@ -72,7 +72,7 @@ module CapUtil
|
|
72
72
|
# so, I'm just defining each option, both in string (how it comes from
|
73
73
|
# the configs) and symbol form.
|
74
74
|
|
75
|
-
options_list.each do |option|
|
75
|
+
(options_list || []).each do |option|
|
76
76
|
@options[option.to_s] = true
|
77
77
|
@options[option.to_sym] = true
|
78
78
|
end
|
data/lib/cap-util/timer.rb
CHANGED
data/lib/cap-util/unset_var.rb
CHANGED
data/lib/cap-util/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -1,22 +1,13 @@
|
|
1
|
-
# this file is automatically required
|
2
|
-
# put test helpers here
|
3
|
-
ENV['CAPUTIL_SILENCE_SAY'] = 'yes'
|
1
|
+
# this file is automatically required when you run `assert`
|
2
|
+
# put any test helpers here
|
4
3
|
|
5
|
-
# add root dir to the load path
|
4
|
+
# add the root dir to the load path
|
6
5
|
$LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
|
7
6
|
|
8
|
-
require
|
9
|
-
require '
|
10
|
-
|
11
|
-
module TestHelpers
|
12
|
-
|
13
|
-
class AnCapUtil
|
14
|
-
include CapUtil
|
7
|
+
# require pry for debugging (`binding.pry`)
|
8
|
+
require 'pry'
|
15
9
|
|
16
|
-
|
17
|
-
@cap = cap
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
10
|
+
ENV['CAPUTIL_SILENCE_SAY'] = 'yes'
|
21
11
|
|
22
|
-
|
12
|
+
require 'cap-util'
|
13
|
+
require 'cap-util/fake_cap'
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'assert'
|
2
|
+
require 'test/support/an_cap_util'
|
2
3
|
|
3
|
-
module
|
4
|
+
module CapUtilSysTests
|
4
5
|
|
5
6
|
class CapUtilTests < Assert::Context
|
6
7
|
desc "the CapUtil module"
|
@@ -26,7 +27,7 @@ module CapUtil
|
|
26
27
|
class CapUtilMixinTests < Assert::Context
|
27
28
|
desc "the CapUtil mixin"
|
28
29
|
setup do
|
29
|
-
@cap_util = TestHelpers::AnCapUtil.new(FakeCap.new)
|
30
|
+
@cap_util = TestHelpers::AnCapUtil.new(CapUtil::FakeCap.new)
|
30
31
|
end
|
31
32
|
subject { @cap_util }
|
32
33
|
|
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'assert'
|
2
|
-
|
3
2
|
require 'cap-util/fake_cap'
|
4
3
|
|
5
|
-
|
4
|
+
class CapUtil::FakeCap
|
6
5
|
|
7
|
-
class
|
6
|
+
class BaseTests < Assert::Context
|
8
7
|
desc "the fake cap helper"
|
9
8
|
setup do
|
10
|
-
@fc = FakeCap.new
|
9
|
+
@fc = CapUtil::FakeCap.new
|
11
10
|
end
|
12
11
|
subject { @fc }
|
13
12
|
|
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'assert'
|
2
|
-
|
3
2
|
require 'cap-util/git_branch'
|
4
3
|
|
5
|
-
|
4
|
+
class CapUtil::GitBranch
|
6
5
|
|
7
|
-
class
|
6
|
+
class BaseTests < Assert::Context
|
8
7
|
desc "the GitBranch util"
|
9
|
-
subject { GitBranch }
|
8
|
+
subject { CapUtil::GitBranch }
|
10
9
|
|
11
10
|
should have_imeth :current
|
12
11
|
|
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'assert'
|
2
|
-
|
3
2
|
require 'cap-util/run'
|
4
3
|
|
5
|
-
|
4
|
+
class CapUtil::LocalCmdRunner
|
6
5
|
|
7
|
-
class
|
6
|
+
class BaseTests < Assert::Context
|
8
7
|
desc "the local cmd runner helper class"
|
9
8
|
setup do
|
10
|
-
@cmd_runner = LocalCmdRunner.new("echo hi")
|
9
|
+
@cmd_runner = CapUtil::LocalCmdRunner.new("echo hi")
|
11
10
|
end
|
12
11
|
subject { @cmd_runner }
|
13
12
|
|
@@ -1,17 +1,16 @@
|
|
1
1
|
require 'assert'
|
2
|
-
|
3
2
|
require 'cap-util/rake_task'
|
4
3
|
|
5
|
-
|
4
|
+
class CapUtil::RakeTask
|
6
5
|
|
7
|
-
class
|
6
|
+
class BaseTests < Assert::Context
|
8
7
|
desc "the rake task util"
|
9
8
|
setup do
|
10
|
-
@fake_cap = FakeCap.new
|
9
|
+
@fake_cap = CapUtil::FakeCap.new
|
11
10
|
@fake_cap.fetch_rake = "bundle exec rake"
|
12
11
|
@fake_cap.current_path = "/a/current/path"
|
13
12
|
@fake_cap.release_path = "/dat/release/path"
|
14
|
-
@rake_task_util = RakeTask.new(@fake_cap, 'a:task:to:run')
|
13
|
+
@rake_task_util = CapUtil::RakeTask.new(@fake_cap, 'a:task:to:run')
|
15
14
|
end
|
16
15
|
subject { @rake_task_util }
|
17
16
|
|
@@ -27,7 +26,7 @@ module CapUtil
|
|
27
26
|
end
|
28
27
|
|
29
28
|
should "run the task with a custom rake if given" do
|
30
|
-
task = RakeTask.new(@fake_cap, '', :rake => '/path/to/rake')
|
29
|
+
task = CapUtil::RakeTask.new(@fake_cap, '', :rake => '/path/to/rake')
|
31
30
|
assert_match '/path/to/rake', task.cmd
|
32
31
|
end
|
33
32
|
|
@@ -36,12 +35,12 @@ module CapUtil
|
|
36
35
|
end
|
37
36
|
|
38
37
|
should "use a custom cap path if given" do
|
39
|
-
task = RakeTask.new(@fake_cap, '', :root => :release_path)
|
38
|
+
task = CapUtil::RakeTask.new(@fake_cap, '', :root => :release_path)
|
40
39
|
assert_match "cd #{@fake_cap.release_path} &&", task.cmd
|
41
40
|
end
|
42
41
|
|
43
42
|
should "use a custom env var string if given" do
|
44
|
-
task = RakeTask.new(@fake_cap, '', :env => "FOO=bar")
|
43
|
+
task = CapUtil::RakeTask.new(@fake_cap, '', :env => "FOO=bar")
|
45
44
|
assert_match "FOO=bar bundle", task.cmd
|
46
45
|
end
|
47
46
|
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'cap-util/server_roles'
|
3
|
+
|
4
|
+
class CapUtil::ServerRoles
|
5
|
+
|
6
|
+
class BaseTests < Assert::Context
|
7
|
+
desc "the ServerRoles handler"
|
8
|
+
setup do
|
9
|
+
roles_yaml = <<YAML
|
10
|
+
---
|
11
|
+
hosts:
|
12
|
+
host1: [primary]
|
13
|
+
host2: []
|
14
|
+
YAML
|
15
|
+
@fake_cap = CapUtil::FakeCap.new
|
16
|
+
@server_roles = CapUtil::ServerRoles.new(@fake_cap, roles_yaml)
|
17
|
+
end
|
18
|
+
subject { @server_roles }
|
19
|
+
|
20
|
+
should have_reader :roles
|
21
|
+
should have_imeth :apply
|
22
|
+
|
23
|
+
should "build cap roles from yaml using the apply meth" do
|
24
|
+
subject.apply
|
25
|
+
roles = @fake_cap.roles.sort{|a,b| a[1] <=> b[1]}
|
26
|
+
|
27
|
+
assert_equal 2, @fake_cap.roles.size
|
28
|
+
assert_equal ['hosts', 'host2', {}], roles.last
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class RoleSetTests < Assert::Context
|
34
|
+
desc "the server roles RoleSet"
|
35
|
+
setup do
|
36
|
+
@roles_hash = {
|
37
|
+
'hosts' => {
|
38
|
+
'host1' => ['primary'],
|
39
|
+
'host2' => []
|
40
|
+
}
|
41
|
+
}
|
42
|
+
@role_set = CapUtil::ServerRoles::RoleSet.new @roles_hash
|
43
|
+
end
|
44
|
+
subject { @role_set }
|
45
|
+
|
46
|
+
should have_reader :role_defs
|
47
|
+
should have_imeth :each
|
48
|
+
|
49
|
+
should "yield the name, hostname, and opts for each host/server when iterating the roles" do
|
50
|
+
exp = [
|
51
|
+
['hosts', 'host1', {:primary => true, 'primary' => true}],
|
52
|
+
['hosts', 'host2', {}]
|
53
|
+
]
|
54
|
+
actual = []
|
55
|
+
subject.each do |name, host, opts|
|
56
|
+
actual << [name, host, opts]
|
57
|
+
end
|
58
|
+
|
59
|
+
assert_equal exp, actual.sort{|a, b| a[1] <=> b[1]}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class RoleDefTests < RoleSetTests
|
64
|
+
desc "the server roles RoleDef"
|
65
|
+
setup do
|
66
|
+
@role_servers_hash = {
|
67
|
+
'host1' => ['primary'],
|
68
|
+
'host2' => []
|
69
|
+
}
|
70
|
+
@role = CapUtil::ServerRoles::RoleDef.new('hosts', @role_servers_hash)
|
71
|
+
end
|
72
|
+
subject { @role }
|
73
|
+
|
74
|
+
should have_reader :name, :servers
|
75
|
+
should have_imeth :apply
|
76
|
+
|
77
|
+
should "build a set of servers from a definition hash" do
|
78
|
+
servs = subject.servers.sort{|a, b| a.hostname <=> b.hostname }
|
79
|
+
|
80
|
+
assert_kind_of ::Array, servs
|
81
|
+
assert_equal 2, servs.size
|
82
|
+
assert_kind_of ServerDef, servs.first
|
83
|
+
assert_equal 'host2', servs.last.hostname
|
84
|
+
assert_equal true, servs.first.options['primary']
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
class ServerDefTests < Assert::Context
|
90
|
+
desc "the server roles ServerDef"
|
91
|
+
setup do
|
92
|
+
@server = CapUtil::ServerRoles::ServerDef.new('host1')
|
93
|
+
end
|
94
|
+
subject { @server }
|
95
|
+
|
96
|
+
should have_readers :hostname, :options
|
97
|
+
|
98
|
+
should "build its hostname from the server name" do
|
99
|
+
assert_equal "host1", subject.hostname
|
100
|
+
end
|
101
|
+
|
102
|
+
should "have no options by defoult" do
|
103
|
+
assert_empty subject.options
|
104
|
+
end
|
105
|
+
|
106
|
+
should "build its options with both string and symbol keys" do
|
107
|
+
server = CapUtil::ServerRoles::ServerDef.new('opts1', 'primary')
|
108
|
+
|
109
|
+
assert_equal true, server.options[:primary]
|
110
|
+
assert_equal true, server.options['primary']
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'assert'
|
2
|
-
|
3
2
|
require 'cap-util/server_roles_yaml'
|
4
3
|
|
5
|
-
|
4
|
+
class CapUtil::ServerRolesYaml
|
6
5
|
|
7
|
-
class
|
6
|
+
class BaseTests < Assert::Context
|
8
7
|
desc "the ServerRolesYaml util"
|
9
8
|
setup do
|
10
|
-
@roles_yaml = ServerRolesYaml.new(FakeCap.new )
|
9
|
+
@roles_yaml = CapUtil::ServerRolesYaml.new(CapUtil::FakeCap.new )
|
11
10
|
end
|
12
11
|
subject { @roles_yaml }
|
13
12
|
|
@@ -20,7 +19,7 @@ module CapUtil
|
|
20
19
|
end
|
21
20
|
|
22
21
|
should "use a custom desc and source if given" do
|
23
|
-
yml = ServerRolesYaml.new(FakeCap.new, {
|
22
|
+
yml = CapUtil::ServerRolesYaml.new(CapUtil::FakeCap.new, {
|
24
23
|
:desc => 'staging',
|
25
24
|
:source => 'the place'
|
26
25
|
})
|
@@ -1,18 +1,17 @@
|
|
1
1
|
require 'assert'
|
2
2
|
require 'fileutils'
|
3
3
|
require 'pathname'
|
4
|
-
|
5
4
|
require 'cap-util/shared_path'
|
6
5
|
|
7
|
-
|
6
|
+
class CapUtil::SharedPath
|
8
7
|
|
9
|
-
class
|
8
|
+
class BaseTests < Assert::Context
|
10
9
|
desc "the SharedPath util"
|
11
10
|
setup do
|
12
|
-
@fake_cap = FakeCap.new
|
11
|
+
@fake_cap = CapUtil::FakeCap.new
|
13
12
|
@fake_cap.shared_path = Pathname.new File.expand_path("tmp/shared")
|
14
13
|
|
15
|
-
@shared_path = SharedPath.new(@fake_cap)
|
14
|
+
@shared_path = CapUtil::SharedPath.new(@fake_cap)
|
16
15
|
end
|
17
16
|
subject { @shared_path }
|
18
17
|
|
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'assert'
|
2
|
-
|
3
2
|
require 'cap-util/timer'
|
4
3
|
|
5
|
-
|
4
|
+
class CapUtil::Timer
|
6
5
|
|
7
|
-
class
|
6
|
+
class BaseTests < Assert::Context
|
8
7
|
desc "the Timer helper class"
|
9
8
|
setup do
|
10
|
-
@timer_util = Timer.new('a timer', :quiet)
|
9
|
+
@timer_util = CapUtil::Timer.new('a timer', :quiet)
|
11
10
|
end
|
12
11
|
subject { @timer_util }
|
13
12
|
|
@@ -41,7 +40,7 @@ module CapUtil
|
|
41
40
|
|
42
41
|
assert_equal exp_end_time, subject.end_time
|
43
42
|
assert_equal (exp_end_time - exp_start_time), subject.elapsed_time
|
44
|
-
assert_equal "0:01", Timer.pretty_time(subject.elapsed_time.to_i)
|
43
|
+
assert_equal "0:01", CapUtil::Timer.pretty_time(subject.elapsed_time.to_i)
|
45
44
|
end
|
46
45
|
|
47
46
|
end
|
@@ -1,14 +1,13 @@
|
|
1
1
|
require 'assert'
|
2
|
-
|
3
2
|
require 'cap-util/unset_var'
|
4
3
|
|
5
|
-
module CapUtil
|
4
|
+
module CapUtil::UnsetVar
|
6
5
|
|
7
|
-
class
|
6
|
+
class BaseTests < Assert::Context
|
8
7
|
desc "the unset var helper"
|
9
8
|
setup do
|
10
9
|
@var_name = 'test'
|
11
|
-
@unset = UnsetVar.new(@var_name)
|
10
|
+
@unset = CapUtil::UnsetVar.new(@var_name)
|
12
11
|
end
|
13
12
|
subject { @unset }
|
14
13
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cap-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,52 +16,52 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-
|
19
|
+
date: 2013-03-25 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
+
name: assert
|
22
23
|
prerelease: false
|
23
|
-
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
25
|
none: false
|
25
26
|
requirements:
|
26
27
|
- - ~>
|
27
28
|
- !ruby/object:Gem::Version
|
28
|
-
hash:
|
29
|
+
hash: 3
|
29
30
|
segments:
|
30
|
-
-
|
31
|
+
- 2
|
31
32
|
- 0
|
32
|
-
version: "
|
33
|
-
requirement: *id001
|
34
|
-
name: assert
|
33
|
+
version: "2.0"
|
35
34
|
type: :development
|
35
|
+
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
+
name: scmd
|
37
38
|
prerelease: false
|
38
|
-
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
40
|
none: false
|
40
41
|
requirements:
|
41
|
-
- -
|
42
|
+
- - ~>
|
42
43
|
- !ruby/object:Gem::Version
|
43
44
|
hash: 3
|
44
45
|
segments:
|
46
|
+
- 2
|
45
47
|
- 0
|
46
|
-
version: "0"
|
47
|
-
requirement: *id002
|
48
|
-
name: capistrano
|
48
|
+
version: "2.0"
|
49
49
|
type: :runtime
|
50
|
+
version_requirements: *id002
|
50
51
|
- !ruby/object:Gem::Dependency
|
52
|
+
name: capistrano
|
51
53
|
prerelease: false
|
52
|
-
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
55
|
none: false
|
54
56
|
requirements:
|
55
|
-
- -
|
57
|
+
- - ">="
|
56
58
|
- !ruby/object:Gem::Version
|
57
59
|
hash: 3
|
58
60
|
segments:
|
59
|
-
- 2
|
60
61
|
- 0
|
61
|
-
version: "
|
62
|
-
requirement: *id003
|
63
|
-
name: scmd
|
62
|
+
version: "0"
|
64
63
|
type: :runtime
|
64
|
+
version_requirements: *id003
|
65
65
|
description: A set of utilities for writing cap tasks.
|
66
66
|
email:
|
67
67
|
- kelly@kellyredding.com
|
@@ -75,7 +75,7 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- .gitignore
|
77
77
|
- Gemfile
|
78
|
-
- LICENSE
|
78
|
+
- LICENSE.txt
|
79
79
|
- README.md
|
80
80
|
- Rakefile
|
81
81
|
- cap-util.gemspec
|
@@ -93,18 +93,18 @@ files:
|
|
93
93
|
- lib/cap-util/timer.rb
|
94
94
|
- lib/cap-util/unset_var.rb
|
95
95
|
- lib/cap-util/version.rb
|
96
|
-
- test/cap_util_tests.rb
|
97
|
-
- test/fake_cap_tests.rb
|
98
|
-
- test/git_branch_tests.rb
|
99
96
|
- test/helper.rb
|
100
|
-
- test/
|
101
|
-
- test/
|
102
|
-
- test/
|
103
|
-
- test/
|
104
|
-
- test/
|
105
|
-
- test/
|
106
|
-
- test/
|
107
|
-
- test/
|
97
|
+
- test/support/an_cap_util.rb
|
98
|
+
- test/system/cap_util_tests.rb
|
99
|
+
- test/unit/fake_cap_tests.rb
|
100
|
+
- test/unit/git_branch_tests.rb
|
101
|
+
- test/unit/local_cmd_runner_tests.rb
|
102
|
+
- test/unit/rake_task_tests.rb
|
103
|
+
- test/unit/server_roles_tests.rb
|
104
|
+
- test/unit/server_roles_yaml_tests.rb
|
105
|
+
- test/unit/shared_path_tests.rb
|
106
|
+
- test/unit/timer_tests.rb
|
107
|
+
- test/unit/unset_var_tests.rb
|
108
108
|
homepage: http://github.com/redding/cap-util
|
109
109
|
licenses: []
|
110
110
|
|
@@ -134,20 +134,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
requirements: []
|
135
135
|
|
136
136
|
rubyforge_project:
|
137
|
-
rubygems_version: 1.8.
|
137
|
+
rubygems_version: 1.8.24
|
138
138
|
signing_key:
|
139
139
|
specification_version: 3
|
140
140
|
summary: A set of utilities for writing cap tasks.
|
141
141
|
test_files:
|
142
|
-
- test/cap_util_tests.rb
|
143
|
-
- test/fake_cap_tests.rb
|
144
|
-
- test/git_branch_tests.rb
|
145
142
|
- test/helper.rb
|
146
|
-
- test/
|
147
|
-
- test/
|
148
|
-
- test/
|
149
|
-
- test/
|
150
|
-
- test/
|
151
|
-
- test/
|
152
|
-
- test/
|
153
|
-
- test/
|
143
|
+
- test/support/an_cap_util.rb
|
144
|
+
- test/system/cap_util_tests.rb
|
145
|
+
- test/unit/fake_cap_tests.rb
|
146
|
+
- test/unit/git_branch_tests.rb
|
147
|
+
- test/unit/local_cmd_runner_tests.rb
|
148
|
+
- test/unit/rake_task_tests.rb
|
149
|
+
- test/unit/server_roles_tests.rb
|
150
|
+
- test/unit/server_roles_yaml_tests.rb
|
151
|
+
- test/unit/shared_path_tests.rb
|
152
|
+
- test/unit/timer_tests.rb
|
153
|
+
- test/unit/unset_var_tests.rb
|
data/test/irb.rb
DELETED
data/test/server_roles_tests.rb
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
require 'assert'
|
2
|
-
|
3
|
-
require 'cap-util/server_roles'
|
4
|
-
|
5
|
-
module CapUtil
|
6
|
-
|
7
|
-
class ServerRolesTests < Assert::Context
|
8
|
-
desc "the ServerRoles handler"
|
9
|
-
setup do
|
10
|
-
roles_yaml = <<YAML
|
11
|
-
---
|
12
|
-
hosts:
|
13
|
-
host1: [primary]
|
14
|
-
host2: []
|
15
|
-
YAML
|
16
|
-
@fake_cap = FakeCap.new
|
17
|
-
@server_roles = ServerRoles.new(@fake_cap, roles_yaml)
|
18
|
-
end
|
19
|
-
subject { @server_roles }
|
20
|
-
|
21
|
-
should have_reader :roles
|
22
|
-
should have_imeth :apply
|
23
|
-
|
24
|
-
should "build cap roles from yaml using the apply meth" do
|
25
|
-
subject.apply
|
26
|
-
roles = @fake_cap.roles.sort{|a,b| a[1] <=> b[1]}
|
27
|
-
|
28
|
-
assert_equal 2, @fake_cap.roles.size
|
29
|
-
assert_equal ['hosts', 'host2.reelfx.com', {}], roles.last
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
class ServerRoles
|
35
|
-
|
36
|
-
class RoleSetTests < Assert::Context
|
37
|
-
desc "the server roles RoleSet"
|
38
|
-
setup do
|
39
|
-
@roles_hash = {
|
40
|
-
'hosts' => {
|
41
|
-
'host1' => ['primary'],
|
42
|
-
'host2' => []
|
43
|
-
}
|
44
|
-
}
|
45
|
-
@role_set = RoleSet.new @roles_hash
|
46
|
-
end
|
47
|
-
subject { @role_set }
|
48
|
-
|
49
|
-
should have_reader :role_defs
|
50
|
-
should have_imeth :each
|
51
|
-
|
52
|
-
should "yield the name, hostname, and opts for each host/server when iterating the roles" do
|
53
|
-
exp = [
|
54
|
-
['hosts', 'host1.reelfx.com', {:primary => true, 'primary' => true}],
|
55
|
-
['hosts', 'host2.reelfx.com', {}]
|
56
|
-
]
|
57
|
-
actual = []
|
58
|
-
subject.each do |name, host, opts|
|
59
|
-
actual << [name, host, opts]
|
60
|
-
end
|
61
|
-
|
62
|
-
assert_equal exp, actual.sort{|a, b| a[1] <=> b[1]}
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
class RoleDefTests < RoleSetTests
|
67
|
-
desc "the server roles RoleDef"
|
68
|
-
setup do
|
69
|
-
@role_servers_hash = {
|
70
|
-
'host1' => ['primary'],
|
71
|
-
'host2' => []
|
72
|
-
}
|
73
|
-
@role = RoleDef.new('hosts', @role_servers_hash)
|
74
|
-
end
|
75
|
-
subject { @role }
|
76
|
-
|
77
|
-
should have_reader :name, :servers
|
78
|
-
should have_imeth :apply
|
79
|
-
|
80
|
-
should "build a set of servers from a definition hash" do
|
81
|
-
servs = subject.servers.sort{|a, b| a.hostname <=> b.hostname }
|
82
|
-
|
83
|
-
assert_kind_of ::Array, servs
|
84
|
-
assert_equal 2, servs.size
|
85
|
-
assert_kind_of ServerDef, servs.first
|
86
|
-
assert_equal 'host2.reelfx.com', servs.last.hostname
|
87
|
-
assert_equal true, servs.first.options['primary']
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
class ServerDefTests < Assert::Context
|
93
|
-
desc "the server roles ServerDef"
|
94
|
-
setup do
|
95
|
-
@server = ServerDef.new('host1')
|
96
|
-
end
|
97
|
-
subject { @server }
|
98
|
-
|
99
|
-
should have_readers :hostname, :options
|
100
|
-
|
101
|
-
should "build its hostname from the server name" do
|
102
|
-
assert_equal "host1.reelfx.com", subject.hostname
|
103
|
-
end
|
104
|
-
|
105
|
-
should "have no options by defoult" do
|
106
|
-
assert_empty subject.options
|
107
|
-
end
|
108
|
-
|
109
|
-
should "build its options with both string and symbol keys" do
|
110
|
-
server = ServerDef.new('opts1', 'primary')
|
111
|
-
|
112
|
-
assert_equal true, server.options[:primary]
|
113
|
-
assert_equal true, server.options['primary']
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|