producer-core 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.travis.yml +3 -0
  2. data/config/cucumber.yaml +1 -0
  3. data/features/{action_echo.feature → actions/echo.feature} +0 -0
  4. data/features/{action_file_append.feature → actions/file_append.feature} +0 -0
  5. data/features/{action_file_replace_content.feature → actions/file_replace_content.feature} +0 -0
  6. data/features/{action_file_write.feature → actions/file_write.feature} +0 -0
  7. data/features/{action_mkdir.feature → actions/mkdir.feature} +0 -0
  8. data/features/{action_sh.feature → actions/sh.feature} +0 -0
  9. data/features/{action_yaml_write.feature → actions/yaml_write.feature} +0 -0
  10. data/features/{cli_debug.feature → cli/debug.feature} +0 -0
  11. data/features/{cli_dry_run.feature → cli/dry_run.feature} +0 -0
  12. data/features/{cli_error_reporting.feature → cli/error_reporting.feature} +0 -0
  13. data/features/{cli_target.feature → cli/target.feature} +0 -0
  14. data/features/{cli_usage.feature → cli/usage.feature} +0 -0
  15. data/features/{cli_verbose.feature → cli/verbose.feature} +0 -0
  16. data/features/{condition_negated_test.feature → condition/negated_test.feature} +0 -0
  17. data/features/{condition_target.feature → condition/target.feature} +0 -0
  18. data/features/{recipe_compose_macro.feature → recipe/compose_macro.feature} +0 -0
  19. data/features/{recipe_macro.feature → recipe/macro.feature} +0 -0
  20. data/features/{registry.feature → recipe/registry.feature} +23 -0
  21. data/features/{recipe_source.feature → recipe/source.feature} +0 -0
  22. data/features/{recipe_target.feature → recipe/target.feature} +0 -0
  23. data/features/{recipe_test_macro.feature → recipe/test_macro.feature} +0 -0
  24. data/features/{ssh_config.feature → ssh/config.feature} +0 -0
  25. data/features/steps/remote_steps.rb +1 -1
  26. data/features/{task_ask.feature → task/ask.feature} +0 -0
  27. data/features/{task_condition.feature → task/condition.feature} +0 -0
  28. data/features/{task_nested_tasks.feature → task/nested_tasks.feature} +0 -0
  29. data/features/{task_target.feature → task/target.feature} +0 -0
  30. data/features/{task_template.feature → task/template.feature} +0 -0
  31. data/features/{test_dir.feature → tests/dir.feature} +0 -0
  32. data/features/{test_env.feature → tests/env.feature} +0 -0
  33. data/features/{test_executable.feature → tests/executable.feature} +0 -0
  34. data/features/{test_file.feature → tests/file.feature} +0 -0
  35. data/features/{test_file_contains.feature → tests/file_contains.feature} +0 -0
  36. data/features/{test_file_eq.feature → tests/file_eq.feature} +0 -0
  37. data/features/{test_file_match.feature → tests/file_match.feature} +0 -0
  38. data/features/{test_shell_command_status.feature → tests/shell_command_status.feature} +0 -0
  39. data/features/{test_yaml_eq.feature → tests/yaml_eq.feature} +0 -0
  40. data/lib/producer/core/cli.rb +2 -1
  41. data/lib/producer/core/env.rb +6 -7
  42. data/lib/producer/core/error_formatter.rb +10 -1
  43. data/lib/producer/core/recipe.rb +3 -8
  44. data/lib/producer/core/task.rb +4 -9
  45. data/lib/producer/core/tests/condition_test.rb +3 -7
  46. data/lib/producer/core/tests/shell_command_status.rb +3 -4
  47. data/lib/producer/core/version.rb +1 -1
  48. data/spec/producer/core/cli_spec.rb +9 -0
  49. data/spec/producer/core/task_spec.rb +12 -0
  50. metadata +77 -75
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.4
@@ -0,0 +1 @@
1
+ default: --require features/support --require features/steps
File without changes
File without changes
File without changes
File without changes
@@ -46,3 +46,26 @@ Feature: key/value registry
46
46
  When I execute the recipe
47
47
  Then the output must not contain "after_fail"
48
48
  And the output must match /\A\w+Error:\s+:no_key/
49
+
50
+ Scenario: `get' keyword accepts a default value
51
+ Given a recipe with:
52
+ """
53
+ task :registry_testing do
54
+ echo get(:some_key, 'some_value')
55
+ end
56
+ """
57
+ When I successfully execute the recipe
58
+ Then the output must contain "some_value"
59
+
60
+ Scenario: `set?' keyword tests wether given key is defined
61
+ Given a recipe with:
62
+ """
63
+ set :some_key, 'some_value'
64
+ task :registry_testing do
65
+ echo 'some_value_set' if set? :some_key
66
+ echo 'other_value' if set? :other_key
67
+ end
68
+ """
69
+ When I execute the recipe
70
+ Then the output must contain "some_value_set"
71
+ And the output must not contain "other_value"
File without changes
@@ -19,7 +19,7 @@ Then /^the remote file "([^"]+)" must contain "([^"]+)"$/ do |path, content|
19
19
  end
20
20
 
21
21
  Then /^the remote file "([^"]+)" must contain exactly "([^"]+)"$/ do |path, content|
22
- check_exact_file_content path, content
22
+ check_file_content path, content
23
23
  end
24
24
 
25
25
  Then /^the remote file "([^"]+)" must match \/([^\/]+)\/$/ do |path, pattern|
File without changes
File without changes
File without changes
File without changes
@@ -17,7 +17,7 @@ module Producer
17
17
  rescue ArgumentError => e
18
18
  stderr.puts e.message
19
19
  exit EX_USAGE
20
- rescue Exception => e
20
+ rescue StandardError => e
21
21
  ef = ErrorFormatter.new(
22
22
  debug: cli.env.debug?,
23
23
  force_cause: [RecipeEvaluationError]
@@ -45,6 +45,7 @@ module Producer
45
45
 
46
46
  def run(worker: Worker.new(@env))
47
47
  evaluate_recipes.each { |recipe| worker.process recipe.tasks }
48
+ ensure
48
49
  @env.cleanup
49
50
  end
50
51
 
@@ -1,6 +1,9 @@
1
1
  module Producer
2
2
  module Core
3
3
  class Env
4
+ extend Forwardable
5
+ def_delegators :@registry, :[]=, :key?
6
+
4
7
  attr_reader :input, :output, :error_output, :registry, :logger
5
8
  attr_accessor :target, :verbose, :debug, :dry_run
6
9
 
@@ -17,17 +20,13 @@ module Producer
17
20
  @remote ||= Remote.new(target)
18
21
  end
19
22
 
20
- def [](key)
21
- @registry.fetch key
23
+ def [](*args)
24
+ @registry.fetch *args
22
25
  rescue KeyError
23
- fail RegistryKeyError, key.inspect
26
+ fail RegistryKeyError, args.first.inspect
24
27
  end
25
28
  alias get []
26
29
 
27
- def []=(key, value)
28
- @registry[key] = value
29
- end
30
-
31
30
  def logger
32
31
  @logger ||= begin
33
32
  logger = Logger.new(output)
@@ -1,6 +1,12 @@
1
1
  module Producer
2
2
  module Core
3
3
  class ErrorFormatter
4
+ FILTERS = [
5
+ /\/producer-\w+\/(?:bin|lib)\//,
6
+ /\/net\/ssh\//,
7
+ /\/net\/sftp\//
8
+ ].freeze
9
+
4
10
  def initialize(debug: false, force_cause: [])
5
11
  @debug = debug
6
12
  @force_cause = force_cause
@@ -22,6 +28,7 @@ module Producer
22
28
  lines.join("\n")
23
29
  end
24
30
 
31
+
25
32
  private
26
33
 
27
34
  def format_exception(exception, filter: true)
@@ -42,7 +49,9 @@ module Producer
42
49
  end
43
50
 
44
51
  def filter_backtrace(backtrace)
45
- backtrace.reject { |l| l =~ /\/producer-\w+\/(?:bin|lib)\// }
52
+ backtrace.reject do |line|
53
+ FILTERS.any? { |filter| line =~ filter }
54
+ end
46
55
  end
47
56
 
48
57
  def indent_backtrace(backtrace)
@@ -19,6 +19,9 @@ module Producer
19
19
  end
20
20
  end
21
21
 
22
+ extend Forwardable
23
+ def_delegator :@env, :[]=, :set
24
+ def_delegator :@env, :[], :get
22
25
  attr_reader :env, :tasks
23
26
 
24
27
  def initialize(env)
@@ -49,14 +52,6 @@ module Producer
49
52
  def test_macro(name, &block)
50
53
  Condition.define_test(name, block)
51
54
  end
52
-
53
- def set(key, value)
54
- env[key] = value
55
- end
56
-
57
- def get(key)
58
- env[key]
59
- end
60
55
  end
61
56
  end
62
57
  end
@@ -14,7 +14,10 @@ module Producer
14
14
  end
15
15
 
16
16
  extend Forwardable
17
- def_delegators :@env, :target
17
+ def_delegators :@name, :to_s
18
+ def_delegators :@env, :target
19
+ def_delegator :@env, :[], :get
20
+ def_delegator :@env, :key?, :set?
18
21
 
19
22
  define_action :echo, Actions::Echo
20
23
  define_action :sh, Actions::ShellCommand
@@ -34,10 +37,6 @@ module Producer
34
37
  @condition = condition
35
38
  end
36
39
 
37
- def to_s
38
- @name.to_s
39
- end
40
-
41
40
  def condition_met?
42
41
  !!@condition
43
42
  end
@@ -55,10 +54,6 @@ module Producer
55
54
  prompter.prompt(question, choices)
56
55
  end
57
56
 
58
- def get(key)
59
- @env[key]
60
- end
61
-
62
57
  def template(path, variables = {})
63
58
  Template.new(path).render variables
64
59
  end
@@ -2,9 +2,9 @@ module Producer
2
2
  module Core
3
3
  module Tests
4
4
  class ConditionTest < Test
5
- def verify
6
- condition.met?
7
- end
5
+ extend Forwardable
6
+ def_delegator :@arguments, :first, :condition_block
7
+ def_delegator :condition, :met?, :verify
8
8
 
9
9
  def condition
10
10
  Condition.evaluate(env, *condition_args, &condition_block)
@@ -13,10 +13,6 @@ module Producer
13
13
  def condition_args
14
14
  arguments.drop 1
15
15
  end
16
-
17
- def condition_block
18
- arguments.first
19
- end
20
16
  end
21
17
  end
22
18
  end
@@ -2,16 +2,15 @@ module Producer
2
2
  module Core
3
3
  module Tests
4
4
  class ShellCommandStatus < Test
5
+ extend Forwardable
6
+ def_delegator :@arguments, :first, :command
7
+
5
8
  def verify
6
9
  remote.execute(command)
7
10
  true
8
11
  rescue RemoteCommandExecutionError
9
12
  false
10
13
  end
11
-
12
- def command
13
- arguments.first
14
- end
15
14
  end
16
15
  end
17
16
  end
@@ -1,5 +1,5 @@
1
1
  module Producer
2
2
  module Core
3
- VERSION = '0.4.2'.freeze
3
+ VERSION = '0.4.3'.freeze
4
4
  end
5
5
  end
@@ -152,6 +152,15 @@ module Producer::Core
152
152
  expect(cli.env).to receive :cleanup
153
153
  cli.run
154
154
  end
155
+
156
+ context 'on error' do
157
+ let(:recipe_file) { fixture_path_for 'recipes/raise.rb' }
158
+
159
+ it 'cleans up the env' do
160
+ expect(cli.env).to receive :cleanup
161
+ cli.run rescue nil
162
+ end
163
+ end
155
164
  end
156
165
 
157
166
  describe '#evaluate_recipes' do
@@ -160,6 +160,18 @@ module Producer::Core
160
160
  end
161
161
  end
162
162
 
163
+ describe '#set?' do
164
+ before { env[:some_key] = :some_value }
165
+
166
+ it 'returns true when given key exists' do
167
+ expect(task.set? :some_key).to be true
168
+ end
169
+
170
+ it 'returns false when given key does not exist' do
171
+ expect(task.set? :other_key).to be false
172
+ end
173
+ end
174
+
163
175
  describe '#target' do
164
176
  before { env.target = :some_target }
165
177
 
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.4.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-14 00:00:00.000000000 Z
12
+ date: 2015-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ssh
@@ -132,33 +132,35 @@ extensions: []
132
132
  extra_rdoc_files: []
133
133
  files:
134
134
  - ".gitignore"
135
+ - ".travis.yml"
135
136
  - Gemfile
136
137
  - Guardfile
137
138
  - LICENSE
138
139
  - Rakefile
139
140
  - bin/producer
140
- - features/action_echo.feature
141
- - features/action_file_append.feature
142
- - features/action_file_replace_content.feature
143
- - features/action_file_write.feature
144
- - features/action_mkdir.feature
145
- - features/action_sh.feature
146
- - features/action_yaml_write.feature
147
- - features/cli_debug.feature
148
- - features/cli_dry_run.feature
149
- - features/cli_error_reporting.feature
150
- - features/cli_target.feature
151
- - features/cli_usage.feature
152
- - features/cli_verbose.feature
153
- - features/condition_negated_test.feature
154
- - features/condition_target.feature
155
- - features/recipe_compose_macro.feature
156
- - features/recipe_macro.feature
157
- - features/recipe_source.feature
158
- - features/recipe_target.feature
159
- - features/recipe_test_macro.feature
160
- - features/registry.feature
161
- - features/ssh_config.feature
141
+ - config/cucumber.yaml
142
+ - features/actions/echo.feature
143
+ - features/actions/file_append.feature
144
+ - features/actions/file_replace_content.feature
145
+ - features/actions/file_write.feature
146
+ - features/actions/mkdir.feature
147
+ - features/actions/sh.feature
148
+ - features/actions/yaml_write.feature
149
+ - features/cli/debug.feature
150
+ - features/cli/dry_run.feature
151
+ - features/cli/error_reporting.feature
152
+ - features/cli/target.feature
153
+ - features/cli/usage.feature
154
+ - features/cli/verbose.feature
155
+ - features/condition/negated_test.feature
156
+ - features/condition/target.feature
157
+ - features/recipe/compose_macro.feature
158
+ - features/recipe/macro.feature
159
+ - features/recipe/registry.feature
160
+ - features/recipe/source.feature
161
+ - features/recipe/target.feature
162
+ - features/recipe/test_macro.feature
163
+ - features/ssh/config.feature
162
164
  - features/steps/etc_steps.rb
163
165
  - features/steps/execution_steps.rb
164
166
  - features/steps/output_steps.rb
@@ -169,20 +171,20 @@ files:
169
171
  - features/support/env_aruba_timeout.rb
170
172
  - features/support/env_cucumber_doc_string.rb
171
173
  - features/support/env_fake_home.rb
172
- - features/task_ask.feature
173
- - features/task_condition.feature
174
- - features/task_nested_tasks.feature
175
- - features/task_target.feature
176
- - features/task_template.feature
177
- - features/test_dir.feature
178
- - features/test_env.feature
179
- - features/test_executable.feature
180
- - features/test_file.feature
181
- - features/test_file_contains.feature
182
- - features/test_file_eq.feature
183
- - features/test_file_match.feature
184
- - features/test_shell_command_status.feature
185
- - features/test_yaml_eq.feature
174
+ - features/task/ask.feature
175
+ - features/task/condition.feature
176
+ - features/task/nested_tasks.feature
177
+ - features/task/target.feature
178
+ - features/task/template.feature
179
+ - features/tests/dir.feature
180
+ - features/tests/env.feature
181
+ - features/tests/executable.feature
182
+ - features/tests/file.feature
183
+ - features/tests/file_contains.feature
184
+ - features/tests/file_eq.feature
185
+ - features/tests/file_match.feature
186
+ - features/tests/shell_command_status.feature
187
+ - features/tests/yaml_eq.feature
186
188
  - lib/producer/core.rb
187
189
  - lib/producer/core/action.rb
188
190
  - lib/producer/core/actions/echo.rb
@@ -290,33 +292,33 @@ required_rubygems_version: !ruby/object:Gem::Requirement
290
292
  version: '0'
291
293
  requirements: []
292
294
  rubyforge_project:
293
- rubygems_version: 1.8.29
295
+ rubygems_version: 1.8.30
294
296
  signing_key:
295
297
  specification_version: 3
296
298
  summary: Provisioning tool
297
299
  test_files:
298
- - features/action_echo.feature
299
- - features/action_file_append.feature
300
- - features/action_file_replace_content.feature
301
- - features/action_file_write.feature
302
- - features/action_mkdir.feature
303
- - features/action_sh.feature
304
- - features/action_yaml_write.feature
305
- - features/cli_debug.feature
306
- - features/cli_dry_run.feature
307
- - features/cli_error_reporting.feature
308
- - features/cli_target.feature
309
- - features/cli_usage.feature
310
- - features/cli_verbose.feature
311
- - features/condition_negated_test.feature
312
- - features/condition_target.feature
313
- - features/recipe_compose_macro.feature
314
- - features/recipe_macro.feature
315
- - features/recipe_source.feature
316
- - features/recipe_target.feature
317
- - features/recipe_test_macro.feature
318
- - features/registry.feature
319
- - features/ssh_config.feature
300
+ - features/actions/echo.feature
301
+ - features/actions/file_append.feature
302
+ - features/actions/file_replace_content.feature
303
+ - features/actions/file_write.feature
304
+ - features/actions/mkdir.feature
305
+ - features/actions/sh.feature
306
+ - features/actions/yaml_write.feature
307
+ - features/cli/debug.feature
308
+ - features/cli/dry_run.feature
309
+ - features/cli/error_reporting.feature
310
+ - features/cli/target.feature
311
+ - features/cli/usage.feature
312
+ - features/cli/verbose.feature
313
+ - features/condition/negated_test.feature
314
+ - features/condition/target.feature
315
+ - features/recipe/compose_macro.feature
316
+ - features/recipe/macro.feature
317
+ - features/recipe/registry.feature
318
+ - features/recipe/source.feature
319
+ - features/recipe/target.feature
320
+ - features/recipe/test_macro.feature
321
+ - features/ssh/config.feature
320
322
  - features/steps/etc_steps.rb
321
323
  - features/steps/execution_steps.rb
322
324
  - features/steps/output_steps.rb
@@ -327,20 +329,20 @@ test_files:
327
329
  - features/support/env_aruba_timeout.rb
328
330
  - features/support/env_cucumber_doc_string.rb
329
331
  - features/support/env_fake_home.rb
330
- - features/task_ask.feature
331
- - features/task_condition.feature
332
- - features/task_nested_tasks.feature
333
- - features/task_target.feature
334
- - features/task_template.feature
335
- - features/test_dir.feature
336
- - features/test_env.feature
337
- - features/test_executable.feature
338
- - features/test_file.feature
339
- - features/test_file_contains.feature
340
- - features/test_file_eq.feature
341
- - features/test_file_match.feature
342
- - features/test_shell_command_status.feature
343
- - features/test_yaml_eq.feature
332
+ - features/task/ask.feature
333
+ - features/task/condition.feature
334
+ - features/task/nested_tasks.feature
335
+ - features/task/target.feature
336
+ - features/task/template.feature
337
+ - features/tests/dir.feature
338
+ - features/tests/env.feature
339
+ - features/tests/executable.feature
340
+ - features/tests/file.feature
341
+ - features/tests/file_contains.feature
342
+ - features/tests/file_eq.feature
343
+ - features/tests/file_match.feature
344
+ - features/tests/shell_command_status.feature
345
+ - features/tests/yaml_eq.feature
344
346
  - spec/fixtures/recipes/empty.rb
345
347
  - spec/fixtures/recipes/raise.rb
346
348
  - spec/fixtures/recipes/some_recipe.rb