producer-core 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +4 -3
  3. data/features/actions/file_replace_content.feature +31 -0
  4. data/features/recipes/registry.feature +21 -0
  5. data/features/steps/remote_steps.rb +8 -0
  6. data/features/tasks/registry.feature +13 -0
  7. data/features/tests/file_contains.feature +28 -0
  8. data/lib/producer/core/action.rb +0 -2
  9. data/lib/producer/core/actions/file_replace_content.rb +27 -0
  10. data/lib/producer/core/condition/dsl.rb +4 -3
  11. data/lib/producer/core/env.rb +15 -5
  12. data/lib/producer/core/recipe/dsl.rb +8 -0
  13. data/lib/producer/core/remote/environment.rb +0 -2
  14. data/lib/producer/core/remote/fs.rb +9 -9
  15. data/lib/producer/core/remote.rb +1 -4
  16. data/lib/producer/core/task/dsl.rb +7 -2
  17. data/lib/producer/core/test.rb +0 -2
  18. data/lib/producer/core/testing/mock_remote.rb +25 -0
  19. data/lib/producer/core/testing.rb +1 -0
  20. data/lib/producer/core/tests/file_contains.rb +18 -0
  21. data/lib/producer/core/version.rb +1 -1
  22. data/lib/producer/core.rb +9 -0
  23. data/producer-core.gemspec +2 -2
  24. data/spec/producer/core/action_spec.rb +1 -42
  25. data/spec/producer/core/actions/echo_spec.rb +11 -8
  26. data/spec/producer/core/actions/file_replace_content_spec.rb +49 -0
  27. data/spec/producer/core/actions/file_writer_spec.rb +20 -17
  28. data/spec/producer/core/actions/mkdir_spec.rb +15 -13
  29. data/spec/producer/core/actions/shell_command_spec.rb +16 -14
  30. data/spec/producer/core/condition/dsl_spec.rb +53 -51
  31. data/spec/producer/core/env_spec.rb +30 -2
  32. data/spec/producer/core/prompter_spec.rb +0 -1
  33. data/spec/producer/core/recipe/dsl_spec.rb +82 -66
  34. data/spec/producer/core/remote/environment_spec.rb +32 -30
  35. data/spec/producer/core/remote/fs_spec.rb +100 -104
  36. data/spec/producer/core/remote_spec.rb +4 -13
  37. data/spec/producer/core/task/dsl_spec.rb +82 -72
  38. data/spec/producer/core/task_spec.rb +1 -1
  39. data/spec/producer/core/test_spec.rb +1 -77
  40. data/spec/producer/core/testing/mock_remote_spec.rb +46 -0
  41. data/spec/producer/core/tests/file_contains_spec.rb +46 -0
  42. data/spec/producer/core/tests/has_dir_spec.rb +15 -18
  43. data/spec/producer/core/tests/has_env_spec.rb +34 -34
  44. data/spec/producer/core/tests/has_file_spec.rb +15 -18
  45. data/spec/spec_helper.rb +3 -3
  46. data/spec/support/shared_action.rb +44 -0
  47. data/spec/support/shared_test.rb +82 -0
  48. data/spec/support/test_env_helpers.rb +34 -0
  49. metadata +33 -9
@@ -1,27 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Producer::Core
4
- describe Tests::HasDir do
5
- let(:env) { Env.new }
6
- let(:path) { 'some_directory' }
7
- subject(:has_dir) { Tests::HasDir.new(env, path) }
4
+ module Tests
5
+ describe HasDir, :env do
6
+ let(:path) { 'some_directory' }
7
+ subject(:has_dir) { HasDir.new(env, path) }
8
8
 
9
- it 'is a kind of test' do
10
- expect(has_dir).to be_a Test
11
- end
12
-
13
- describe '#verify', :ssh do
14
- before { sftp_story }
9
+ it_behaves_like 'test'
15
10
 
16
- it 'delegates the call on remote FS' do
17
- expect(env.remote.fs).to receive(:dir?).with(path)
18
- has_dir.verify
19
- end
11
+ describe '#verify' do
12
+ it 'delegates the call on remote FS' do
13
+ expect(remote_fs).to receive(:dir?).with(path)
14
+ has_dir.verify
15
+ end
20
16
 
21
- it 'returns the dir existence' do
22
- existence = double 'existence'
23
- allow(env.remote.fs).to receive(:dir?) { existence }
24
- expect(has_dir.verify).to be existence
17
+ it 'returns the dir existence' do
18
+ existence = double 'existence'
19
+ allow(remote_fs).to receive(:dir?) { existence }
20
+ expect(has_dir.verify).to be existence
21
+ end
25
22
  end
26
23
  end
27
24
  end
@@ -1,40 +1,40 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Producer::Core
4
- describe Tests::HasEnv do
5
- let(:env) { Env.new }
6
- let(:variable_name) { :some_variable_name }
7
- subject(:has_env) { Tests::HasEnv.new(env, variable_name) }
8
-
9
- it 'is a kind of test' do
10
- expect(has_env).to be_a Test
11
- end
12
-
13
- describe '#verify' do
14
- let(:environment) { double 'environment' }
15
-
16
- before do
17
- allow(env.remote).to receive(:environment) { environment }
18
- end
19
-
20
- it 'stringifies the queried variable name' do
21
- expect(environment).to receive(:key?).with(kind_of(String))
22
- has_env.verify
23
- end
24
-
25
- it 'upcases the queried variable name' do
26
- expect(environment).to receive(:key?).with('SOME_VARIABLE_NAME')
27
- has_env.verify
28
- end
29
-
30
- it 'returns true when remote environment var is defined' do
31
- allow(environment).to receive(:key?) { true }
32
- expect(has_env.verify).to be true
33
- end
34
-
35
- it 'returns false when remote environment var is not defined' do
36
- allow(environment).to receive(:key?) { false }
37
- expect(has_env.verify).to be false
4
+ module Tests
5
+ describe HasEnv do
6
+ let(:env) { Env.new }
7
+ let(:variable_name) { :some_variable_name }
8
+ subject(:has_env) { HasEnv.new(env, variable_name) }
9
+
10
+ it_behaves_like 'test'
11
+
12
+ describe '#verify' do
13
+ let(:environment) { double 'environment' }
14
+
15
+ before do
16
+ allow(env.remote).to receive(:environment) { environment }
17
+ end
18
+
19
+ it 'stringifies the queried variable name' do
20
+ expect(environment).to receive(:key?).with(kind_of(String))
21
+ has_env.verify
22
+ end
23
+
24
+ it 'upcases the queried variable name' do
25
+ expect(environment).to receive(:key?).with('SOME_VARIABLE_NAME')
26
+ has_env.verify
27
+ end
28
+
29
+ it 'returns true when remote environment var is defined' do
30
+ allow(environment).to receive(:key?) { true }
31
+ expect(has_env.verify).to be true
32
+ end
33
+
34
+ it 'returns false when remote environment var is not defined' do
35
+ allow(environment).to receive(:key?) { false }
36
+ expect(has_env.verify).to be false
37
+ end
38
38
  end
39
39
  end
40
40
  end
@@ -1,27 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Producer::Core
4
- describe Tests::HasFile do
5
- let(:env) { Env.new }
6
- let(:filepath) { 'some_file' }
7
- subject(:has_file) { Tests::HasFile.new(env, filepath) }
4
+ module Tests
5
+ describe HasFile, :env do
6
+ let(:filepath) { 'some_file' }
7
+ subject(:has_file) { HasFile.new(env, filepath) }
8
8
 
9
- it 'is a kind of test' do
10
- expect(has_file).to be_a Test
11
- end
12
-
13
- describe '#verify', :ssh do
14
- before { sftp_story }
9
+ it_behaves_like 'test'
15
10
 
16
- it 'delegates the call on remote FS' do
17
- expect(env.remote.fs).to receive(:file?).with(filepath)
18
- has_file.verify
19
- end
11
+ describe '#verify' do
12
+ it 'delegates the call on remote FS' do
13
+ expect(remote_fs).to receive(:file?).with(filepath)
14
+ has_file.verify
15
+ end
20
16
 
21
- it 'returns the file existence' do
22
- existence = double 'existence'
23
- allow(env.remote.fs).to receive(:file?) { existence }
24
- expect(has_file.verify).to be existence
17
+ it 'returns the file existence' do
18
+ existence = double 'existence'
19
+ allow(remote_fs).to receive(:file?) { existence }
20
+ expect(has_file.verify).to be existence
21
+ end
25
22
  end
26
23
  end
27
24
  end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  require 'producer/core'
2
2
 
3
- require 'support/exit_helpers'
4
- require 'support/fixtures_helpers'
5
- require 'support/net_ssh_story_helpers'
3
+ Dir['spec/support/**/*.rb'].map { |e| require e.gsub 'spec/', '' }
6
4
 
7
5
 
8
6
  RSpec.configure do |c|
9
7
  c.treat_symbols_as_metadata_keys_with_true_values = true
10
8
 
9
+ c.include TestEnvHelpers, :env
10
+
11
11
  c.include NetSSHStoryHelpers, :ssh
12
12
  c.before(:each, :ssh) do
13
13
  allow(Net::SSH).to receive(:start) { connection }
@@ -0,0 +1,44 @@
1
+ module Producer::Core
2
+ shared_examples 'action' do
3
+ include TestEnvHelpers
4
+
5
+ let(:arguments) { [:some, :arguments] }
6
+ subject(:action) { described_class.new(env, *arguments) }
7
+
8
+ describe '#env' do
9
+ it 'returns the assigned env' do
10
+ expect(action.env).to be env
11
+ end
12
+ end
13
+
14
+ describe '#arguments' do
15
+ it 'returns the assigned arguments' do
16
+ expect(action.arguments).to eq arguments
17
+ end
18
+ end
19
+
20
+ describe '#input' do
21
+ it 'returns env input' do
22
+ expect(action.input).to be env.input
23
+ end
24
+ end
25
+
26
+ describe '#output' do
27
+ it 'returns env output' do
28
+ expect(action.output).to be env.output
29
+ end
30
+ end
31
+
32
+ describe '#remote' do
33
+ it 'returns env remote' do
34
+ expect(action.remote).to be env.remote
35
+ end
36
+ end
37
+
38
+ describe '#fs' do
39
+ it 'returns env remote fs' do
40
+ expect(action.fs).to be env.remote.fs
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,82 @@
1
+ module Producer::Core
2
+ shared_examples 'test' do
3
+ include TestEnvHelpers
4
+
5
+ let(:arguments) { [:some, :arguments] }
6
+ subject(:test) { described_class.new(env, *arguments) }
7
+
8
+ describe '#initialize' do
9
+ it 'assigns the env' do
10
+ expect(test.env).to be env
11
+ end
12
+
13
+ it 'assigns the arguments' do
14
+ expect(test.arguments).to eq arguments
15
+ end
16
+
17
+ it 'assigns negated as false by default' do
18
+ expect(test).to_not be_negated
19
+ end
20
+
21
+ context 'when negated option is true' do
22
+ subject(:test) { described_class.new(env, *arguments, negated: true) }
23
+
24
+ it 'assigns negated as true' do
25
+ expect(test).to be_negated
26
+ end
27
+ end
28
+ end
29
+
30
+ describe '#remote' do
31
+ it 'returns env remote' do
32
+ expect(test.remote).to be test.env.remote
33
+ end
34
+ end
35
+
36
+ describe '#fs' do
37
+ it 'returns env remote fs' do
38
+ expect(test.fs).to be test.env.remote.fs
39
+ end
40
+ end
41
+
42
+ describe '#negated?' do
43
+ it 'returns false' do
44
+ expect(test.negated?).to be false
45
+ end
46
+
47
+ context 'when test is negated' do
48
+ subject(:test) { described_class.new(env, *arguments, negated: true) }
49
+
50
+ it 'returns true' do
51
+ expect(test.negated?).to be true
52
+ end
53
+ end
54
+ end
55
+
56
+ describe '#pass?' do
57
+ it 'returns true when #verify is true' do
58
+ allow(test).to receive(:verify) { true }
59
+ expect(test.pass?).to be true
60
+ end
61
+
62
+ it 'returns false when #verify is false' do
63
+ allow(test).to receive(:verify) { false }
64
+ expect(test.pass?).to be false
65
+ end
66
+
67
+ context 'when test is negated' do
68
+ subject(:test) { described_class.new(env, *arguments, negated: true) }
69
+
70
+ it 'returns false when #verify is true' do
71
+ allow(test).to receive(:verify) { true }
72
+ expect(test.pass?).to be false
73
+ end
74
+
75
+ it 'returns true when #verify is false' do
76
+ allow(test).to receive(:verify) { false }
77
+ expect(test.pass?).to be true
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,34 @@
1
+ module TestEnvHelpers
2
+ require 'producer/core/testing'
3
+
4
+ def env
5
+ @_env ||= build_env
6
+ end
7
+
8
+ def output
9
+ env.output.string
10
+ end
11
+
12
+ def remote_fs
13
+ env.remote.fs
14
+ end
15
+
16
+ def expect_execution(command)
17
+ opts = { expected_from: caller.first }
18
+ RSpec::Mocks.expect_message(env.remote, :execute, opts).with(command)
19
+ end
20
+
21
+
22
+ private
23
+
24
+ def build_env
25
+ Producer::Core::Env.new(output: StringIO.new, remote: build_remote)
26
+ end
27
+
28
+ def build_remote
29
+ fs = RSpec::Mocks::Mock.new('remote fs', __declared_as: 'Double')
30
+ remote = Producer::Core::Testing::MockRemote.new('some_host.test')
31
+ remote.define_singleton_method(:fs) { fs }
32
+ remote
33
+ end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: producer-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
@@ -14,30 +14,30 @@ dependencies:
14
14
  name: net-ssh
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 2.7.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 2.7.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: net-sftp
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 2.1.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 2.1.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -109,6 +109,7 @@ files:
109
109
  - Rakefile
110
110
  - bin/producer
111
111
  - features/actions/echo.feature
112
+ - features/actions/file_replace_content.feature
112
113
  - features/actions/file_write.feature
113
114
  - features/actions/mkdir.feature
114
115
  - features/actions/sh.feature
@@ -116,6 +117,7 @@ files:
116
117
  - features/recipes/ask.feature
117
118
  - features/recipes/evaluation.feature
118
119
  - features/recipes/macro.feature
120
+ - features/recipes/registry.feature
119
121
  - features/recipes/source.feature
120
122
  - features/recipes/target.feature
121
123
  - features/ssh/config.feature
@@ -128,6 +130,8 @@ files:
128
130
  - features/support/ssh.rb
129
131
  - features/tasks/condition.feature
130
132
  - features/tasks/evaluation.feature
133
+ - features/tasks/registry.feature
134
+ - features/tests/file_contains.feature
131
135
  - features/tests/has_dir.feature
132
136
  - features/tests/has_env.feature
133
137
  - features/tests/has_file.feature
@@ -135,6 +139,7 @@ files:
135
139
  - lib/producer/core.rb
136
140
  - lib/producer/core/action.rb
137
141
  - lib/producer/core/actions/echo.rb
142
+ - lib/producer/core/actions/file_replace_content.rb
138
143
  - lib/producer/core/actions/file_writer.rb
139
144
  - lib/producer/core/actions/mkdir.rb
140
145
  - lib/producer/core/actions/shell_command.rb
@@ -152,6 +157,9 @@ files:
152
157
  - lib/producer/core/task.rb
153
158
  - lib/producer/core/task/dsl.rb
154
159
  - lib/producer/core/test.rb
160
+ - lib/producer/core/testing.rb
161
+ - lib/producer/core/testing/mock_remote.rb
162
+ - lib/producer/core/tests/file_contains.rb
155
163
  - lib/producer/core/tests/has_dir.rb
156
164
  - lib/producer/core/tests/has_env.rb
157
165
  - lib/producer/core/tests/has_file.rb
@@ -163,6 +171,7 @@ files:
163
171
  - spec/fixtures/recipes/throw.rb
164
172
  - spec/producer/core/action_spec.rb
165
173
  - spec/producer/core/actions/echo_spec.rb
174
+ - spec/producer/core/actions/file_replace_content_spec.rb
166
175
  - spec/producer/core/actions/file_writer_spec.rb
167
176
  - spec/producer/core/actions/mkdir_spec.rb
168
177
  - spec/producer/core/actions/shell_command_spec.rb
@@ -179,6 +188,8 @@ files:
179
188
  - spec/producer/core/task/dsl_spec.rb
180
189
  - spec/producer/core/task_spec.rb
181
190
  - spec/producer/core/test_spec.rb
191
+ - spec/producer/core/testing/mock_remote_spec.rb
192
+ - spec/producer/core/tests/file_contains_spec.rb
182
193
  - spec/producer/core/tests/has_dir_spec.rb
183
194
  - spec/producer/core/tests/has_env_spec.rb
184
195
  - spec/producer/core/tests/has_file_spec.rb
@@ -187,6 +198,9 @@ files:
187
198
  - spec/support/exit_helpers.rb
188
199
  - spec/support/fixtures_helpers.rb
189
200
  - spec/support/net_ssh_story_helpers.rb
201
+ - spec/support/shared_action.rb
202
+ - spec/support/shared_test.rb
203
+ - spec/support/test_env_helpers.rb
190
204
  homepage: https://rubygems.org/gems/producer-core
191
205
  licenses: []
192
206
  metadata: {}
@@ -212,6 +226,7 @@ specification_version: 4
212
226
  summary: Provisioning tool
213
227
  test_files:
214
228
  - features/actions/echo.feature
229
+ - features/actions/file_replace_content.feature
215
230
  - features/actions/file_write.feature
216
231
  - features/actions/mkdir.feature
217
232
  - features/actions/sh.feature
@@ -219,6 +234,7 @@ test_files:
219
234
  - features/recipes/ask.feature
220
235
  - features/recipes/evaluation.feature
221
236
  - features/recipes/macro.feature
237
+ - features/recipes/registry.feature
222
238
  - features/recipes/source.feature
223
239
  - features/recipes/target.feature
224
240
  - features/ssh/config.feature
@@ -231,6 +247,8 @@ test_files:
231
247
  - features/support/ssh.rb
232
248
  - features/tasks/condition.feature
233
249
  - features/tasks/evaluation.feature
250
+ - features/tasks/registry.feature
251
+ - features/tests/file_contains.feature
234
252
  - features/tests/has_dir.feature
235
253
  - features/tests/has_env.feature
236
254
  - features/tests/has_file.feature
@@ -240,6 +258,7 @@ test_files:
240
258
  - spec/fixtures/recipes/throw.rb
241
259
  - spec/producer/core/action_spec.rb
242
260
  - spec/producer/core/actions/echo_spec.rb
261
+ - spec/producer/core/actions/file_replace_content_spec.rb
243
262
  - spec/producer/core/actions/file_writer_spec.rb
244
263
  - spec/producer/core/actions/mkdir_spec.rb
245
264
  - spec/producer/core/actions/shell_command_spec.rb
@@ -256,6 +275,8 @@ test_files:
256
275
  - spec/producer/core/task/dsl_spec.rb
257
276
  - spec/producer/core/task_spec.rb
258
277
  - spec/producer/core/test_spec.rb
278
+ - spec/producer/core/testing/mock_remote_spec.rb
279
+ - spec/producer/core/tests/file_contains_spec.rb
259
280
  - spec/producer/core/tests/has_dir_spec.rb
260
281
  - spec/producer/core/tests/has_env_spec.rb
261
282
  - spec/producer/core/tests/has_file_spec.rb
@@ -264,4 +285,7 @@ test_files:
264
285
  - spec/support/exit_helpers.rb
265
286
  - spec/support/fixtures_helpers.rb
266
287
  - spec/support/net_ssh_story_helpers.rb
288
+ - spec/support/shared_action.rb
289
+ - spec/support/shared_test.rb
290
+ - spec/support/test_env_helpers.rb
267
291
  has_rdoc: