capistrano 3.4.0 → 3.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +129 -0
  3. data/.github/issue_template.md +19 -0
  4. data/.github/pull_request_template.md +22 -0
  5. data/.github/release-drafter.yml +17 -0
  6. data/.github/workflows/push.yml +12 -0
  7. data/.gitignore +8 -5
  8. data/.rubocop.yml +62 -0
  9. data/CHANGELOG.md +1 -307
  10. data/CONTRIBUTING.md +63 -93
  11. data/DEVELOPMENT.md +127 -0
  12. data/Dangerfile +1 -0
  13. data/Gemfile +40 -3
  14. data/LICENSE.txt +1 -1
  15. data/README.md +127 -44
  16. data/RELEASING.md +17 -0
  17. data/Rakefile +13 -2
  18. data/UPGRADING-3.7.md +86 -0
  19. data/bin/cap +1 -1
  20. data/capistrano.gemspec +21 -24
  21. data/features/deploy.feature +35 -1
  22. data/features/doctor.feature +11 -0
  23. data/features/installation.feature +8 -3
  24. data/features/stage_failure.feature +9 -0
  25. data/features/step_definitions/assertions.rb +51 -18
  26. data/features/step_definitions/cap_commands.rb +9 -0
  27. data/features/step_definitions/setup.rb +53 -9
  28. data/features/subdirectory.feature +9 -0
  29. data/features/support/env.rb +5 -5
  30. data/features/support/remote_command_helpers.rb +12 -6
  31. data/features/support/vagrant_helpers.rb +17 -11
  32. data/lib/Capfile +1 -1
  33. data/lib/capistrano/all.rb +10 -10
  34. data/lib/capistrano/application.rb +47 -34
  35. data/lib/capistrano/configuration/empty_filter.rb +9 -0
  36. data/lib/capistrano/configuration/filter.rb +17 -47
  37. data/lib/capistrano/configuration/host_filter.rb +29 -0
  38. data/lib/capistrano/configuration/null_filter.rb +9 -0
  39. data/lib/capistrano/configuration/plugin_installer.rb +51 -0
  40. data/lib/capistrano/configuration/question.rb +31 -9
  41. data/lib/capistrano/configuration/role_filter.rb +29 -0
  42. data/lib/capistrano/configuration/scm_resolver.rb +149 -0
  43. data/lib/capistrano/configuration/server.rb +29 -23
  44. data/lib/capistrano/configuration/servers.rb +21 -14
  45. data/lib/capistrano/configuration/validated_variables.rb +110 -0
  46. data/lib/capistrano/configuration/variables.rb +112 -0
  47. data/lib/capistrano/configuration.rb +91 -44
  48. data/lib/capistrano/defaults.rb +26 -4
  49. data/lib/capistrano/deploy.rb +1 -1
  50. data/lib/capistrano/doctor/environment_doctor.rb +19 -0
  51. data/lib/capistrano/doctor/gems_doctor.rb +45 -0
  52. data/lib/capistrano/doctor/output_helpers.rb +79 -0
  53. data/lib/capistrano/doctor/servers_doctor.rb +105 -0
  54. data/lib/capistrano/doctor/variables_doctor.rb +74 -0
  55. data/lib/capistrano/doctor.rb +6 -0
  56. data/lib/capistrano/dotfile.rb +1 -2
  57. data/lib/capistrano/dsl/env.rb +9 -47
  58. data/lib/capistrano/dsl/paths.rb +11 -25
  59. data/lib/capistrano/dsl/stages.rb +14 -2
  60. data/lib/capistrano/dsl/task_enhancements.rb +7 -12
  61. data/lib/capistrano/dsl.rb +47 -16
  62. data/lib/capistrano/framework.rb +1 -1
  63. data/lib/capistrano/i18n.rb +32 -24
  64. data/lib/capistrano/immutable_task.rb +30 -0
  65. data/lib/capistrano/install.rb +1 -1
  66. data/lib/capistrano/plugin.rb +95 -0
  67. data/lib/capistrano/proc_helpers.rb +13 -0
  68. data/lib/capistrano/scm/git.rb +100 -0
  69. data/lib/capistrano/scm/hg.rb +55 -0
  70. data/lib/capistrano/scm/plugin.rb +13 -0
  71. data/lib/capistrano/scm/svn.rb +56 -0
  72. data/lib/capistrano/scm/tasks/git.rake +73 -0
  73. data/lib/capistrano/scm/tasks/hg.rake +53 -0
  74. data/lib/capistrano/scm/tasks/svn.rake +53 -0
  75. data/lib/capistrano/scm.rb +7 -20
  76. data/lib/capistrano/setup.rb +20 -6
  77. data/lib/capistrano/tasks/console.rake +4 -8
  78. data/lib/capistrano/tasks/deploy.rake +105 -73
  79. data/lib/capistrano/tasks/doctor.rake +24 -0
  80. data/lib/capistrano/tasks/framework.rake +13 -14
  81. data/lib/capistrano/tasks/install.rake +14 -15
  82. data/lib/capistrano/templates/Capfile +21 -10
  83. data/lib/capistrano/templates/deploy.rb.erb +17 -26
  84. data/lib/capistrano/templates/stage.rb.erb +9 -9
  85. data/lib/capistrano/upload_task.rb +1 -1
  86. data/lib/capistrano/version.rb +1 -1
  87. data/lib/capistrano/version_validator.rb +5 -10
  88. data/spec/integration/dsl_spec.rb +289 -240
  89. data/spec/integration_spec_helper.rb +3 -5
  90. data/spec/lib/capistrano/application_spec.rb +23 -39
  91. data/spec/lib/capistrano/configuration/empty_filter_spec.rb +17 -0
  92. data/spec/lib/capistrano/configuration/filter_spec.rb +83 -85
  93. data/spec/lib/capistrano/configuration/host_filter_spec.rb +71 -0
  94. data/spec/lib/capistrano/configuration/null_filter_spec.rb +17 -0
  95. data/spec/lib/capistrano/configuration/plugin_installer_spec.rb +98 -0
  96. data/spec/lib/capistrano/configuration/question_spec.rb +58 -26
  97. data/spec/lib/capistrano/configuration/role_filter_spec.rb +80 -0
  98. data/spec/lib/capistrano/configuration/scm_resolver_spec.rb +55 -0
  99. data/spec/lib/capistrano/configuration/server_spec.rb +106 -113
  100. data/spec/lib/capistrano/configuration/servers_spec.rb +129 -145
  101. data/spec/lib/capistrano/configuration_spec.rb +224 -63
  102. data/spec/lib/capistrano/doctor/environment_doctor_spec.rb +44 -0
  103. data/spec/lib/capistrano/doctor/gems_doctor_spec.rb +67 -0
  104. data/spec/lib/capistrano/doctor/output_helpers_spec.rb +47 -0
  105. data/spec/lib/capistrano/doctor/servers_doctor_spec.rb +86 -0
  106. data/spec/lib/capistrano/doctor/variables_doctor_spec.rb +89 -0
  107. data/spec/lib/capistrano/dsl/paths_spec.rb +97 -59
  108. data/spec/lib/capistrano/dsl/task_enhancements_spec.rb +57 -37
  109. data/spec/lib/capistrano/dsl_spec.rb +84 -11
  110. data/spec/lib/capistrano/immutable_task_spec.rb +31 -0
  111. data/spec/lib/capistrano/plugin_spec.rb +84 -0
  112. data/spec/lib/capistrano/scm/git_spec.rb +184 -0
  113. data/spec/lib/capistrano/scm/hg_spec.rb +109 -0
  114. data/spec/lib/capistrano/scm/svn_spec.rb +137 -0
  115. data/spec/lib/capistrano/scm_spec.rb +7 -8
  116. data/spec/lib/capistrano/upload_task_spec.rb +7 -7
  117. data/spec/lib/capistrano/version_validator_spec.rb +61 -46
  118. data/spec/lib/capistrano_spec.rb +2 -3
  119. data/spec/spec_helper.rb +21 -8
  120. data/spec/support/Vagrantfile +9 -10
  121. data/spec/support/tasks/database.rake +3 -3
  122. data/spec/support/tasks/fail.rake +4 -3
  123. data/spec/support/tasks/failed.rake +2 -2
  124. data/spec/support/tasks/plugin.rake +6 -0
  125. data/spec/support/tasks/root.rake +4 -4
  126. data/spec/support/test_app.rb +64 -39
  127. metadata +100 -55
  128. data/.travis.yml +0 -13
  129. data/features/remote_file_task.feature +0 -14
  130. data/lib/capistrano/git.rb +0 -46
  131. data/lib/capistrano/hg.rb +0 -43
  132. data/lib/capistrano/svn.rb +0 -38
  133. data/lib/capistrano/tasks/git.rake +0 -81
  134. data/lib/capistrano/tasks/hg.rake +0 -52
  135. data/lib/capistrano/tasks/svn.rake +0 -52
  136. data/spec/lib/capistrano/git_spec.rb +0 -81
  137. data/spec/lib/capistrano/hg_spec.rb +0 -81
  138. data/spec/lib/capistrano/svn_spec.rb +0 -79
@@ -1,65 +1,62 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  module Capistrano
4
4
  class Configuration
5
5
  describe Servers do
6
6
  let(:servers) { Servers.new }
7
7
 
8
- describe 'adding a role' do
9
-
10
- it 'adds two new server instances' do
11
- expect{servers.add_role(:app, %w{1 2})}.
12
- to change{servers.count}.from(0).to(2)
8
+ describe "adding a role" do
9
+ it "adds two new server instances" do
10
+ expect { servers.add_role(:app, %w{1 2}) }
11
+ .to change { servers.count }.from(0).to(2)
13
12
  end
14
13
 
15
- it 'handles de-duplification within roles' do
14
+ it "handles de-duplification within roles" do
16
15
  servers.add_role(:app, %w{1})
17
16
  servers.add_role(:app, %w{1})
18
17
  expect(servers.count).to eq 1
19
18
  end
20
19
 
21
- it 'handles de-duplification within roles with users' do
22
- servers.add_role(:app, %w{1}, user: 'nick')
23
- servers.add_role(:app, %w{1}, user: 'fred')
20
+ it "handles de-duplification within roles with users" do
21
+ servers.add_role(:app, %w{1}, user: "nick")
22
+ servers.add_role(:app, %w{1}, user: "fred")
24
23
  expect(servers.count).to eq 1
25
24
  end
26
25
 
27
- it 'accepts instances of server objects' do
28
- servers.add_role(:app, [Capistrano::Configuration::Server.new('example.net'), 'example.com'])
26
+ it "accepts instances of server objects" do
27
+ servers.add_role(:app, [Capistrano::Configuration::Server.new("example.net"), "example.com"])
29
28
  expect(servers.roles_for([:app]).length).to eq 2
30
29
  end
31
30
 
32
- it 'accepts non-enumerable types' do
33
- servers.add_role(:app, '1')
31
+ it "accepts non-enumerable types" do
32
+ servers.add_role(:app, "1")
34
33
  expect(servers.roles_for([:app]).count).to eq 1
35
34
  end
36
35
 
37
- it 'creates distinct server properties' do
38
- servers.add_role(:db, %w{1 2}, db: { port: 1234 } )
39
- servers.add_host('1', db: { master: true })
36
+ it "creates distinct server properties" do
37
+ servers.add_role(:db, %w{1 2}, db: { port: 1234 })
38
+ servers.add_host("1", db: { master: true })
40
39
  expect(servers.count).to eq(2)
41
40
  expect(servers.roles_for([:db]).count).to eq 2
42
- expect(servers.find(){|s| s.hostname == '1'}.properties.db).to eq({ port: 1234, master: true })
43
- expect(servers.find(){|s| s.hostname == '2'}.properties.db).to eq({ port: 1234 })
41
+ expect(servers.find { |s| s.hostname == "1" }.properties.db).to eq(port: 1234, master: true)
42
+ expect(servers.find { |s| s.hostname == "2" }.properties.db).to eq(port: 1234)
44
43
  end
45
-
46
44
  end
47
45
 
48
- describe 'adding a role to an existing server' do
46
+ describe "adding a role to an existing server" do
49
47
  before do
50
48
  servers.add_role(:web, %w{1 2})
51
49
  servers.add_role(:app, %w{1 2})
52
50
  end
53
51
 
54
- it 'adds new roles to existing servers' do
52
+ it "adds new roles to existing servers" do
55
53
  expect(servers.count).to eq 2
56
54
  end
57
-
58
55
  end
59
56
 
60
- describe 'collecting server roles' do
57
+ describe "collecting server roles" do
61
58
  let(:app) { Set.new([:app]) }
62
- let(:web_app) { Set.new([:web, :app]) }
59
+ let(:web_app) { Set.new(%i(web app)) }
63
60
  let(:web) { Set.new([:web]) }
64
61
 
65
62
  before do
@@ -67,280 +64,267 @@ module Capistrano
67
64
  servers.add_role(:web, %w{2 3 4})
68
65
  end
69
66
 
70
- it 'returns an array of the roles' do
67
+ it "returns an array of the roles" do
71
68
  expect(servers.roles_for([:app]).collect(&:roles)).to eq [app, web_app, web_app]
72
69
  expect(servers.roles_for([:web]).collect(&:roles)).to eq [web_app, web_app, web]
73
70
  end
74
71
  end
75
72
 
76
- describe 'finding the primary server' do
73
+ describe "finding the primary server" do
77
74
  after do
78
75
  Configuration.reset!
79
76
  end
80
- it 'takes the first server if none have the primary property' do
77
+ it "takes the first server if none have the primary property" do
81
78
  servers.add_role(:app, %w{1 2})
82
- expect(servers.fetch_primary(:app).hostname).to eq('1')
79
+ expect(servers.fetch_primary(:app).hostname).to eq("1")
83
80
  end
84
81
 
85
- it 'takes the first server with the primary have the primary flag' do
82
+ it "takes the first server with the primary have the primary flag" do
86
83
  servers.add_role(:app, %w{1 2})
87
- servers.add_host('2', primary: true)
88
- expect(servers.fetch_primary(:app).hostname).to eq('2')
84
+ servers.add_host("2", primary: true)
85
+ expect(servers.fetch_primary(:app).hostname).to eq("2")
89
86
  end
90
87
 
91
- it 'ignores any on_filters' do
92
- Configuration.env.set :filter, { host: '1'}
88
+ it "ignores any on_filters" do
89
+ Configuration.env.set :filter, host: "1"
93
90
  servers.add_role(:app, %w{1 2})
94
- servers.add_host('2', primary: true)
95
- expect(servers.fetch_primary(:app).hostname).to eq('2')
91
+ servers.add_host("2", primary: true)
92
+ expect(servers.fetch_primary(:app).hostname).to eq("2")
96
93
  end
97
94
  end
98
95
 
99
- describe 'fetching servers' do
96
+ describe "fetching servers" do
100
97
  before do
101
98
  servers.add_role(:app, %w{1 2})
102
99
  servers.add_role(:web, %w{2 3})
103
100
  end
104
101
 
105
- it 'returns the correct app servers' do
102
+ it "returns the correct app servers" do
106
103
  expect(servers.roles_for([:app]).map(&:hostname)).to eq %w{1 2}
107
104
  end
108
105
 
109
- it 'returns the correct web servers' do
106
+ it "returns the correct web servers" do
110
107
  expect(servers.roles_for([:web]).map(&:hostname)).to eq %w{2 3}
111
108
  end
112
109
 
113
- it 'returns the correct app and web servers' do
114
- expect(servers.roles_for([:app, :web]).map(&:hostname)).to eq %w{1 2 3}
110
+ it "returns the correct app and web servers" do
111
+ expect(servers.roles_for(%i(app web)).map(&:hostname)).to eq %w{1 2 3}
115
112
  end
116
113
 
117
- it 'returns all servers' do
114
+ it "returns all servers" do
118
115
  expect(servers.roles_for([:all]).map(&:hostname)).to eq %w{1 2 3}
119
116
  end
120
117
  end
121
118
 
122
- describe 'adding a server' do
123
-
119
+ describe "adding a server" do
124
120
  before do
125
- servers.add_host('1', roles: [:app, 'web'], test: :value)
121
+ servers.add_host("1", roles: [:app, "web"], test: :value)
126
122
  end
127
123
 
128
- it 'can create a server with properties' do
129
- expect(servers.roles_for([:app]).first.hostname).to eq '1'
130
- expect(servers.roles_for([:web]).first.hostname).to eq '1'
124
+ it "can create a server with properties" do
125
+ expect(servers.roles_for([:app]).first.hostname).to eq "1"
126
+ expect(servers.roles_for([:web]).first.hostname).to eq "1"
131
127
  expect(servers.roles_for([:all]).first.properties.test).to eq :value
132
128
  expect(servers.roles_for([:all]).first.properties.keys).to eq [:test]
133
129
  end
134
130
 
135
- it 'can accept multiple servers with the same hostname but different ports or users' do
136
- servers.add_host('1', roles: [:app, 'web'], test: :value, port: 12)
137
- servers.add_host('1', roles: [:app, 'web'], test: :value, port: 34)
138
- servers.add_host('1', roles: [:app, 'web'], test: :value, user: 'root')
139
- servers.add_host('1', roles: [:app, 'web'], test: :value, user: 'deployer')
140
- servers.add_host('1', roles: [:app, 'web'], test: :value, user: 'root', port: 34)
141
- servers.add_host('1', roles: [:app, 'web'], test: :value, user: 'deployer', port: 34)
142
- servers.add_host('1', roles: [:app, 'web'], test: :value, user: 'deployer', port: 56)
143
- expect(servers.count).to eq(1)
131
+ it "can accept multiple servers with the same hostname but different ports or users" do
132
+ servers.add_host("1", roles: [:app, "web"], test: :value, port: 12)
133
+ expect(servers.count).to eq(2)
134
+ servers.add_host("1", roles: [:app, "web"], test: :value, port: 34)
135
+ servers.add_host("1", roles: [:app, "web"], test: :value, user: "root")
136
+ servers.add_host("1", roles: [:app, "web"], test: :value, user: "deployer")
137
+ servers.add_host("1", roles: [:app, "web"], test: :value, user: "root", port: 34)
138
+ servers.add_host("1", roles: [:app, "web"], test: :value, user: "deployer", port: 34)
139
+ servers.add_host("1", roles: [:app, "web"], test: :value, user: "deployer", port: 56)
140
+ expect(servers.count).to eq(4)
144
141
  end
145
142
 
146
143
  describe "with a :user property" do
147
-
148
- it 'sets the server ssh username' do
149
- servers.add_host('1', roles: [:app, 'web'], user: 'nick')
144
+ it "sets the server ssh username" do
145
+ servers.add_host("1", roles: [:app, "web"], user: "nick")
150
146
  expect(servers.count).to eq(1)
151
- expect(servers.roles_for([:all]).first.user).to eq 'nick'
147
+ expect(servers.roles_for([:all]).first.user).to eq "nick"
152
148
  end
153
149
 
154
- it 'overwrites the value of a user specified in the hostname' do
155
- servers.add_host('brian@1', roles: [:app, 'web'], user: 'nick')
150
+ it "overwrites the value of a user specified in the hostname" do
151
+ servers.add_host("brian@1", roles: [:app, "web"], user: "nick")
156
152
  expect(servers.count).to eq(1)
157
- expect(servers.roles_for([:all]).first.user).to eq 'nick'
153
+ expect(servers.roles_for([:all]).first.user).to eq "nick"
158
154
  end
159
-
160
155
  end
161
156
 
162
- it 'overwrites the value of a previously defined scalar property' do
163
- servers.add_host('1', roles: [:app, 'web'], test: :volatile)
157
+ it "overwrites the value of a previously defined scalar property" do
158
+ servers.add_host("1", roles: [:app, "web"], test: :volatile)
164
159
  expect(servers.count).to eq(1)
165
160
  expect(servers.roles_for([:all]).first.properties.test).to eq :volatile
166
161
  end
167
162
 
168
- it 'merges previously defined hash properties' do
169
- servers.add_host('1', roles: [:b], db: { port: 1234 })
170
- servers.add_host('1', roles: [:b], db: { master: true })
163
+ it "merges previously defined hash properties" do
164
+ servers.add_host("1", roles: [:b], db: { port: 1234 })
165
+ servers.add_host("1", roles: [:b], db: { master: true })
171
166
  expect(servers.count).to eq(1)
172
- expect(servers.roles_for([:b]).first.properties.db).to eq({ port: 1234, master: true })
167
+ expect(servers.roles_for([:b]).first.properties.db).to eq(port: 1234, master: true)
173
168
  end
174
169
 
175
- it 'concatenates previously defined array properties' do
176
- servers.add_host('1', roles: [:b], steps: [1,3,5])
177
- servers.add_host('1', roles: [:b], steps: [1,9])
170
+ it "concatenates previously defined array properties" do
171
+ servers.add_host("1", roles: [:b], steps: [1, 3, 5])
172
+ servers.add_host("1", roles: [:b], steps: [1, 9])
178
173
  expect(servers.count).to eq(1)
179
- expect(servers.roles_for([:b]).first.properties.steps).to eq([1,3,5,1,9])
174
+ expect(servers.roles_for([:b]).first.properties.steps).to eq([1, 3, 5, 1, 9])
180
175
  end
181
176
 
182
- it 'merges previously defined set properties' do
183
- servers.add_host('1', roles: [:b], endpoints: Set[123,333])
184
- servers.add_host('1', roles: [:b], endpoints: Set[222,333])
177
+ it "merges previously defined set properties" do
178
+ servers.add_host("1", roles: [:b], endpoints: Set[123, 333])
179
+ servers.add_host("1", roles: [:b], endpoints: Set[222, 333])
185
180
  expect(servers.count).to eq(1)
186
- expect(servers.roles_for([:b]).first.properties.endpoints).to eq(Set[123,222,333])
181
+ expect(servers.roles_for([:b]).first.properties.endpoints).to eq(Set[123, 222, 333])
187
182
  end
188
183
 
189
- it 'adds array property value only ones for a new host' do
190
- servers.add_host('2', roles: [:array_test], array_property: [1,2])
191
- expect(servers.roles_for([:array_test]).first.properties.array_property).to eq [1,2]
184
+ it "adds array property value only ones for a new host" do
185
+ servers.add_host("2", roles: [:array_test], array_property: [1, 2])
186
+ expect(servers.roles_for([:array_test]).first.properties.array_property).to eq [1, 2]
192
187
  end
193
188
 
194
- it 'updates roles when custom user defined' do
195
- servers.add_host('1', roles: ['foo'], user: 'custom')
196
- servers.add_host('1', roles: ['bar'], user: 'custom')
197
- expect(servers.roles_for([:foo]).first.hostname).to eq '1'
198
- expect(servers.roles_for([:bar]).first.hostname).to eq '1'
189
+ it "updates roles when custom user defined" do
190
+ servers.add_host("1", roles: ["foo"], user: "custom")
191
+ servers.add_host("1", roles: ["bar"], user: "custom")
192
+ expect(servers.roles_for([:foo]).first.hostname).to eq "1"
193
+ expect(servers.roles_for([:bar]).first.hostname).to eq "1"
199
194
  end
200
195
 
201
- it 'updates roles when custom port defined' do
202
- servers.add_host('1', roles: ['foo'], port: 1234)
203
- servers.add_host('1', roles: ['bar'], port: 1234)
204
- expect(servers.roles_for([:foo]).first.hostname).to eq '1'
205
- expect(servers.roles_for([:bar]).first.hostname).to eq '1'
196
+ it "updates roles when custom port defined" do
197
+ servers.add_host("1", roles: ["foo"], port: 1234)
198
+ servers.add_host("1", roles: ["bar"], port: 1234)
199
+ expect(servers.roles_for([:foo]).first.hostname).to eq "1"
200
+ expect(servers.roles_for([:bar]).first.hostname).to eq "1"
206
201
  end
207
-
208
202
  end
209
203
 
210
- describe 'selecting roles' do
211
-
204
+ describe "selecting roles" do
212
205
  before do
213
- servers.add_host('1', roles: :app, active: true)
214
- servers.add_host('2', roles: :app)
206
+ servers.add_host("1", roles: :app, active: true)
207
+ servers.add_host("2", roles: :app)
215
208
  end
216
209
 
217
- it 'is empty if the filter would remove all matching hosts' do
210
+ it "is empty if the filter would remove all matching hosts" do
218
211
  expect(servers.roles_for([:app, select: :inactive])).to be_empty
219
212
  end
220
213
 
221
- it 'can filter hosts by properties on the host object using symbol as shorthand' do
214
+ it "can filter hosts by properties on the host object using symbol as shorthand" do
222
215
  expect(servers.roles_for([:app, filter: :active]).length).to eq 1
223
216
  end
224
217
 
225
- it 'can select hosts by properties on the host object using symbol as shorthand' do
218
+ it "can select hosts by properties on the host object using symbol as shorthand" do
226
219
  expect(servers.roles_for([:app, select: :active]).length).to eq 1
227
220
  end
228
221
 
229
- it 'can filter hosts by properties on the host using a regular proc' do
222
+ it "can filter hosts by properties on the host using a regular proc" do
230
223
  expect(servers.roles_for([:app, filter: ->(h) { h.properties.active }]).length).to eq 1
231
224
  end
232
225
 
233
- it 'can select hosts by properties on the host using a regular proc' do
226
+ it "can select hosts by properties on the host using a regular proc" do
234
227
  expect(servers.roles_for([:app, select: ->(h) { h.properties.active }]).length).to eq 1
235
228
  end
236
229
 
237
- it 'is empty if the regular proc filter would remove all matching hosts' do
230
+ it "is empty if the regular proc filter would remove all matching hosts" do
238
231
  expect(servers.roles_for([:app, select: ->(h) { h.properties.inactive }])).to be_empty
239
232
  end
240
-
241
233
  end
242
234
 
243
- describe 'excluding by property' do
244
-
235
+ describe "excluding by property" do
245
236
  before do
246
- servers.add_host('1', roles: :app, active: true)
247
- servers.add_host('2', roles: :app, active: true, no_release: true)
237
+ servers.add_host("1", roles: :app, active: true)
238
+ servers.add_host("2", roles: :app, active: true, no_release: true)
248
239
  end
249
240
 
250
- it 'is empty if the filter would remove all matching hosts' do
241
+ it "is empty if the filter would remove all matching hosts" do
251
242
  hosts = servers.roles_for([:app, exclude: :active])
252
243
  expect(hosts.map(&:hostname)).to be_empty
253
244
  end
254
245
 
255
- it 'returns the servers without the attributes specified' do
246
+ it "returns the servers without the attributes specified" do
256
247
  hosts = servers.roles_for([:app, exclude: :no_release])
257
248
  expect(hosts.map(&:hostname)).to eq %w{1}
258
249
  end
259
250
 
260
- it 'can exclude hosts by properties on the host using a regular proc' do
251
+ it "can exclude hosts by properties on the host using a regular proc" do
261
252
  hosts = servers.roles_for([:app, exclude: ->(h) { h.properties.no_release }])
262
253
  expect(hosts.map(&:hostname)).to eq %w{1}
263
254
  end
264
255
 
265
- it 'is empty if the regular proc filter would remove all matching hosts' do
256
+ it "is empty if the regular proc filter would remove all matching hosts" do
266
257
  hosts = servers.roles_for([:app, exclude: ->(h) { h.properties.active }])
267
258
  expect(hosts.map(&:hostname)).to be_empty
268
259
  end
269
-
270
260
  end
271
261
 
272
- describe 'filtering roles internally' do
273
-
262
+ describe "filtering roles internally" do
274
263
  before do
275
- servers.add_host('1', roles: :app, active: true)
276
- servers.add_host('2', roles: :app)
277
- servers.add_host('3', roles: :web)
278
- servers.add_host('4', roles: :web)
279
- servers.add_host('5', roles: :db)
264
+ servers.add_host("1", roles: :app, active: true)
265
+ servers.add_host("2", roles: :app)
266
+ servers.add_host("3", roles: :web)
267
+ servers.add_host("4", roles: :web)
268
+ servers.add_host("5", roles: :db)
280
269
  end
281
270
 
282
271
  subject { servers.roles_for(roles).map(&:hostname) }
283
272
 
284
- context 'with the ROLES environment variable set' do
285
-
273
+ context "with the ROLES environment variable set" do
286
274
  before do
287
- ENV.stubs(:[]).with('ROLES').returns('web,db')
288
- ENV.stubs(:[]).with('HOSTS').returns(nil)
275
+ ENV.stubs(:[]).with("ROLES").returns("web,db")
276
+ ENV.stubs(:[]).with("HOSTS").returns(nil)
289
277
  end
290
278
 
291
- context 'when selecting all roles' do
279
+ context "when selecting all roles" do
292
280
  let(:roles) { [:all] }
293
- it 'ignores it' do
281
+ it "ignores it" do
294
282
  expect(subject).to eq %w{1 2 3 4 5}
295
283
  end
296
284
  end
297
285
 
298
- context 'when selecting specific roles' do
299
- let(:roles) { [:app, :web] }
300
- it 'ignores it' do
286
+ context "when selecting specific roles" do
287
+ let(:roles) { %i(app web) }
288
+ it "ignores it" do
301
289
  expect(subject).to eq %w{1 2 3 4}
302
290
  end
303
291
  end
304
292
 
305
- context 'when selecting roles not included in ROLE' do
293
+ context "when selecting roles not included in ROLE" do
306
294
  let(:roles) { [:app] }
307
- it 'ignores it' do
295
+ it "ignores it" do
308
296
  expect(subject).to eq %w{1 2}
309
297
  end
310
298
  end
311
-
312
299
  end
313
300
 
314
- context 'with the HOSTS environment variable set' do
315
-
301
+ context "with the HOSTS environment variable set" do
316
302
  before do
317
- ENV.stubs(:[]).with('ROLES').returns(nil)
318
- ENV.stubs(:[]).with('HOSTS').returns('3,5')
303
+ ENV.stubs(:[]).with("ROLES").returns(nil)
304
+ ENV.stubs(:[]).with("HOSTS").returns("3,5")
319
305
  end
320
306
 
321
- context 'when selecting all roles' do
307
+ context "when selecting all roles" do
322
308
  let(:roles) { [:all] }
323
- it 'ignores it' do
309
+ it "ignores it" do
324
310
  expect(subject).to eq %w{1 2 3 4 5}
325
311
  end
326
312
  end
327
313
 
328
- context 'when selecting specific roles' do
329
- let(:roles) { [:app, :web] }
330
- it 'ignores it' do
314
+ context "when selecting specific roles" do
315
+ let(:roles) { %i(app web) }
316
+ it "ignores it" do
331
317
  expect(subject).to eq %w{1 2 3 4}
332
318
  end
333
319
  end
334
320
 
335
- context 'when selecting no roles' do
321
+ context "when selecting no roles" do
336
322
  let(:roles) { [] }
337
- it 'ignores it' do
323
+ it "ignores it" do
338
324
  expect(subject).to be_empty
339
325
  end
340
326
  end
341
-
342
327
  end
343
-
344
328
  end
345
329
  end
346
330
  end