producer-core 0.3.0 → 0.3.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.
- checksums.yaml +4 -4
- data/features/{test_negated_test.feature → condition_negated_test.feature} +15 -8
- data/features/{recipe_ask.feature → task_ask.feature} +1 -1
- data/lib/producer/core/cli.rb +1 -1
- data/lib/producer/core/condition.rb +33 -4
- data/lib/producer/core/recipe/file_evaluator.rb +14 -0
- data/lib/producer/core/recipe.rb +36 -6
- data/lib/producer/core/task.rb +32 -6
- data/lib/producer/core/version.rb +1 -1
- data/lib/producer/core/worker.rb +5 -7
- data/lib/producer/core.rb +2 -4
- data/spec/producer/core/condition_spec.rb +105 -21
- data/spec/producer/core/recipe/file_evaluator_spec.rb +22 -0
- data/spec/producer/core/recipe_spec.rb +75 -16
- data/spec/producer/core/task_spec.rb +102 -36
- data/spec/producer/core/worker_spec.rb +8 -14
- metadata +10 -16
- data/lib/producer/core/condition/dsl.rb +0 -48
- data/lib/producer/core/recipe/dsl.rb +0 -61
- data/lib/producer/core/task/dsl.rb +0 -50
- data/spec/producer/core/condition/dsl_spec.rb +0 -116
- data/spec/producer/core/recipe/dsl_spec.rb +0 -140
- data/spec/producer/core/task/dsl_spec.rb +0 -123
@@ -2,62 +2,90 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Producer::Core
|
4
4
|
describe Task do
|
5
|
-
|
6
|
-
let(:action) { double 'action' }
|
7
|
-
let(:condition) { double 'condition' }
|
8
|
-
subject(:task) { Task.new(name, [action], condition) }
|
5
|
+
class SomeAction < Action; end
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
let(:env) { Env.new }
|
8
|
+
let(:name) { :some_task }
|
9
|
+
let(:condition) { :some_condition }
|
10
|
+
subject(:task) { described_class.new(env, name, [], condition) }
|
11
|
+
|
12
|
+
%w[
|
13
|
+
echo
|
14
|
+
sh
|
15
|
+
mkdir
|
16
|
+
file_append
|
17
|
+
file_replace_content
|
18
|
+
file_write
|
19
|
+
].each do |action|
|
20
|
+
it "has `#{action}' action defined" do
|
21
|
+
expect(task).to respond_to action.to_sym
|
22
|
+
end
|
23
|
+
end
|
16
24
|
|
17
|
-
|
25
|
+
describe '.define_action' do
|
26
|
+
before { described_class.define_action(:some_action, SomeAction) }
|
18
27
|
|
19
|
-
it '
|
20
|
-
expect(task).to
|
28
|
+
it 'defines a new action keyword' do
|
29
|
+
expect(task).to respond_to :some_action
|
21
30
|
end
|
22
31
|
|
23
|
-
context '
|
24
|
-
it '
|
25
|
-
expect
|
32
|
+
context 'when an action keyword is called' do
|
33
|
+
it 'registers the action' do
|
34
|
+
expect { task.some_action }.to change { task.actions.count }.by 1
|
26
35
|
end
|
27
36
|
|
28
|
-
it '
|
29
|
-
|
37
|
+
it 'registers the action with current env' do
|
38
|
+
task.some_action
|
39
|
+
expect(task.actions.first.env).to be env
|
30
40
|
end
|
31
41
|
|
32
|
-
it '
|
33
|
-
|
42
|
+
it 'registers the action with given arguments' do
|
43
|
+
task.some_action :foo, :bar
|
44
|
+
expect(task.actions.first.arguments).to eq %i[foo bar]
|
34
45
|
end
|
35
46
|
end
|
36
47
|
end
|
37
48
|
|
38
|
-
describe '
|
39
|
-
|
40
|
-
|
49
|
+
describe '.evaluate' do
|
50
|
+
let(:code) { proc { condition { :condition }; some_action } }
|
51
|
+
let(:arguments) { [] }
|
52
|
+
subject(:task) { described_class.evaluate(env, name, *arguments, &code) }
|
53
|
+
|
54
|
+
before { described_class.define_action(:some_action, SomeAction) }
|
55
|
+
|
56
|
+
it 'returns an evaluated task' do
|
57
|
+
expect(task).to be_a Task
|
41
58
|
end
|
42
59
|
|
43
|
-
it '
|
44
|
-
expect(task.
|
60
|
+
it 'evaluates the task condition' do
|
61
|
+
expect(task.condition).to be_a Condition
|
45
62
|
end
|
46
63
|
|
47
|
-
it '
|
48
|
-
expect(task.
|
64
|
+
it 'evaluates the task actions' do
|
65
|
+
expect(task.actions).to match [
|
66
|
+
an_instance_of(SomeAction)
|
67
|
+
]
|
49
68
|
end
|
50
69
|
|
51
|
-
context 'when
|
52
|
-
|
70
|
+
context 'when task arguments are given' do
|
71
|
+
let(:code) { proc { |a, b| throw a } }
|
72
|
+
let(:arguments) { %i[foo bar] }
|
53
73
|
|
54
|
-
it '
|
55
|
-
expect
|
74
|
+
it 'passes arguments as block parameters during evaluation' do
|
75
|
+
expect { task }.to throw_symbol :foo
|
56
76
|
end
|
77
|
+
end
|
78
|
+
end
|
57
79
|
|
58
|
-
|
59
|
-
|
60
|
-
|
80
|
+
describe '#initialize' do
|
81
|
+
subject(:task) { described_class.new(env, name) }
|
82
|
+
|
83
|
+
it 'assigns no action' do
|
84
|
+
expect(task.actions).to be_empty
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'assigns a truthy condition' do
|
88
|
+
expect(task.condition).to be_truthy
|
61
89
|
end
|
62
90
|
end
|
63
91
|
|
@@ -69,7 +97,7 @@ module Producer::Core
|
|
69
97
|
|
70
98
|
describe '#condition_met?' do
|
71
99
|
context 'when condition is truthy' do
|
72
|
-
let(:condition) {
|
100
|
+
let(:condition) { true }
|
73
101
|
|
74
102
|
it 'returns true' do
|
75
103
|
expect(task.condition_met?).to be true
|
@@ -77,12 +105,50 @@ module Producer::Core
|
|
77
105
|
end
|
78
106
|
|
79
107
|
context 'when condition is falsy' do
|
80
|
-
let(:condition) {
|
108
|
+
let(:condition) { false }
|
81
109
|
|
82
110
|
it 'returns false' do
|
83
111
|
expect(task.condition_met?).to be false
|
84
112
|
end
|
85
113
|
end
|
86
114
|
end
|
115
|
+
|
116
|
+
describe '#condition' do
|
117
|
+
it 'returns current condition' do
|
118
|
+
expect(task.condition).to eq :some_condition
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when a block is given' do
|
122
|
+
it 'assigns a new evaluated condition' do
|
123
|
+
task.condition { :some_new_condition }
|
124
|
+
expect(task.condition.return_value).to eq :some_new_condition
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#ask' do
|
130
|
+
let(:question) { 'Which letter?' }
|
131
|
+
let(:choices) { [[:a, ?A], [:b, ?B]] }
|
132
|
+
let(:prompter) { instance_spy Prompter }
|
133
|
+
subject(:ask) { task.ask question, choices, prompter: prompter }
|
134
|
+
|
135
|
+
it 'prompts for choices' do
|
136
|
+
ask
|
137
|
+
expect(prompter).to have_received(:prompt).with(question, choices)
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'returns selected choice' do
|
141
|
+
allow(prompter).to receive(:prompt) { :choice }
|
142
|
+
expect(ask).to eq :choice
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe '#get' do
|
147
|
+
before { env[:some_key] = :some_value }
|
148
|
+
|
149
|
+
it 'fetches a value from the registry at given index' do
|
150
|
+
expect(task.get :some_key).to eq :some_value
|
151
|
+
end
|
152
|
+
end
|
87
153
|
end
|
88
154
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Producer::Core
|
4
4
|
describe Worker do
|
5
|
-
let(:env) {
|
5
|
+
let(:env) { Env.new }
|
6
6
|
subject(:worker) { described_class.new(env) }
|
7
7
|
|
8
8
|
describe '#process' do
|
@@ -12,7 +12,7 @@ module Producer::Core
|
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'when dry run is enabled' do
|
15
|
-
before {
|
15
|
+
before { env.dry_run = true }
|
16
16
|
|
17
17
|
it 'warns dry run is enabled' do
|
18
18
|
expect(env).to receive(:log).with(
|
@@ -25,12 +25,12 @@ module Producer::Core
|
|
25
25
|
end
|
26
26
|
|
27
27
|
describe '#process_task' do
|
28
|
+
let(:env) { instance_spy Env, dry_run?: false }
|
28
29
|
let(:action) { double('action', to_s: 'echo').as_null_object }
|
29
|
-
let(:
|
30
|
-
let(:task) { Task.new(task_name, [action]) }
|
30
|
+
let(:task) { Task.new(env, :some_task, [action]) }
|
31
31
|
|
32
32
|
it 'logs task info' do
|
33
|
-
expect(env).to receive(:log).with /\ATask:
|
33
|
+
expect(env).to receive(:log).with /\ATask: `some_task'/
|
34
34
|
worker.process_task task
|
35
35
|
end
|
36
36
|
|
@@ -41,7 +41,7 @@ module Producer::Core
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'logs the task as beeing applied' do
|
44
|
-
expect(env).to receive(:log).with
|
44
|
+
expect(env).to receive(:log).with /some_task.+applying\.\.\.\z/
|
45
45
|
worker.process_task task
|
46
46
|
end
|
47
47
|
|
@@ -61,7 +61,7 @@ module Producer::Core
|
|
61
61
|
end
|
62
62
|
|
63
63
|
context 'when task condition is not met' do
|
64
|
-
|
64
|
+
before { task.condition { false } }
|
65
65
|
|
66
66
|
it 'does not apply the actions' do
|
67
67
|
expect(action).not_to receive :apply
|
@@ -69,16 +69,10 @@ module Producer::Core
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'logs the task as beeing skipped' do
|
72
|
-
expect(env).to receive(:log).with
|
72
|
+
expect(env).to receive(:log).with /some_task.+skipped\z/
|
73
73
|
worker.process_task task
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
77
|
-
|
78
|
-
describe '#env' do
|
79
|
-
it 'returns the assigned env' do
|
80
|
-
expect(worker.env).to be env
|
81
|
-
end
|
82
|
-
end
|
83
77
|
end
|
84
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: producer-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibault Jouan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|
@@ -132,7 +132,7 @@ files:
|
|
132
132
|
- features/cli_target.feature
|
133
133
|
- features/cli_usage.feature
|
134
134
|
- features/cli_verbose.feature
|
135
|
-
- features/
|
135
|
+
- features/condition_negated_test.feature
|
136
136
|
- features/recipe_macro.feature
|
137
137
|
- features/recipe_source.feature
|
138
138
|
- features/recipe_target.feature
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- features/support/env_aruba_timeout.rb
|
150
150
|
- features/support/env_cucumber_doc_string.rb
|
151
151
|
- features/support/env_fake_home.rb
|
152
|
+
- features/task_ask.feature
|
152
153
|
- features/task_condition.feature
|
153
154
|
- features/test_dir.feature
|
154
155
|
- features/test_env.feature
|
@@ -156,7 +157,6 @@ files:
|
|
156
157
|
- features/test_file.feature
|
157
158
|
- features/test_file_contains.feature
|
158
159
|
- features/test_file_eq.feature
|
159
|
-
- features/test_negated_test.feature
|
160
160
|
- features/test_shell_command_status.feature
|
161
161
|
- lib/producer/core.rb
|
162
162
|
- lib/producer/core/action.rb
|
@@ -168,18 +168,16 @@ files:
|
|
168
168
|
- lib/producer/core/actions/shell_command.rb
|
169
169
|
- lib/producer/core/cli.rb
|
170
170
|
- lib/producer/core/condition.rb
|
171
|
-
- lib/producer/core/condition/dsl.rb
|
172
171
|
- lib/producer/core/env.rb
|
173
172
|
- lib/producer/core/errors.rb
|
174
173
|
- lib/producer/core/logger_formatter.rb
|
175
174
|
- lib/producer/core/prompter.rb
|
176
175
|
- lib/producer/core/recipe.rb
|
177
|
-
- lib/producer/core/recipe/
|
176
|
+
- lib/producer/core/recipe/file_evaluator.rb
|
178
177
|
- lib/producer/core/remote.rb
|
179
178
|
- lib/producer/core/remote/environment.rb
|
180
179
|
- lib/producer/core/remote/fs.rb
|
181
180
|
- lib/producer/core/task.rb
|
182
|
-
- lib/producer/core/task/dsl.rb
|
183
181
|
- lib/producer/core/test.rb
|
184
182
|
- lib/producer/core/testing.rb
|
185
183
|
- lib/producer/core/testing/mock_remote.rb
|
@@ -206,17 +204,15 @@ files:
|
|
206
204
|
- spec/producer/core/actions/mkdir_spec.rb
|
207
205
|
- spec/producer/core/actions/shell_command_spec.rb
|
208
206
|
- spec/producer/core/cli_spec.rb
|
209
|
-
- spec/producer/core/condition/dsl_spec.rb
|
210
207
|
- spec/producer/core/condition_spec.rb
|
211
208
|
- spec/producer/core/env_spec.rb
|
212
209
|
- spec/producer/core/logger_formatter_spec.rb
|
213
210
|
- spec/producer/core/prompter_spec.rb
|
214
|
-
- spec/producer/core/recipe/
|
211
|
+
- spec/producer/core/recipe/file_evaluator_spec.rb
|
215
212
|
- spec/producer/core/recipe_spec.rb
|
216
213
|
- spec/producer/core/remote/environment_spec.rb
|
217
214
|
- spec/producer/core/remote/fs_spec.rb
|
218
215
|
- spec/producer/core/remote_spec.rb
|
219
|
-
- spec/producer/core/task/dsl_spec.rb
|
220
216
|
- spec/producer/core/task_spec.rb
|
221
217
|
- spec/producer/core/test_spec.rb
|
222
218
|
- spec/producer/core/testing/mock_remote_spec.rb
|
@@ -255,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
255
251
|
version: '0'
|
256
252
|
requirements: []
|
257
253
|
rubyforge_project:
|
258
|
-
rubygems_version: 2.
|
254
|
+
rubygems_version: 2.2.2
|
259
255
|
signing_key:
|
260
256
|
specification_version: 4
|
261
257
|
summary: Provisioning tool
|
@@ -270,7 +266,7 @@ test_files:
|
|
270
266
|
- features/cli_target.feature
|
271
267
|
- features/cli_usage.feature
|
272
268
|
- features/cli_verbose.feature
|
273
|
-
- features/
|
269
|
+
- features/condition_negated_test.feature
|
274
270
|
- features/recipe_macro.feature
|
275
271
|
- features/recipe_source.feature
|
276
272
|
- features/recipe_target.feature
|
@@ -287,6 +283,7 @@ test_files:
|
|
287
283
|
- features/support/env_aruba_timeout.rb
|
288
284
|
- features/support/env_cucumber_doc_string.rb
|
289
285
|
- features/support/env_fake_home.rb
|
286
|
+
- features/task_ask.feature
|
290
287
|
- features/task_condition.feature
|
291
288
|
- features/test_dir.feature
|
292
289
|
- features/test_env.feature
|
@@ -294,7 +291,6 @@ test_files:
|
|
294
291
|
- features/test_file.feature
|
295
292
|
- features/test_file_contains.feature
|
296
293
|
- features/test_file_eq.feature
|
297
|
-
- features/test_negated_test.feature
|
298
294
|
- features/test_shell_command_status.feature
|
299
295
|
- spec/fixtures/recipes/empty.rb
|
300
296
|
- spec/fixtures/recipes/raise.rb
|
@@ -308,17 +304,15 @@ test_files:
|
|
308
304
|
- spec/producer/core/actions/mkdir_spec.rb
|
309
305
|
- spec/producer/core/actions/shell_command_spec.rb
|
310
306
|
- spec/producer/core/cli_spec.rb
|
311
|
-
- spec/producer/core/condition/dsl_spec.rb
|
312
307
|
- spec/producer/core/condition_spec.rb
|
313
308
|
- spec/producer/core/env_spec.rb
|
314
309
|
- spec/producer/core/logger_formatter_spec.rb
|
315
310
|
- spec/producer/core/prompter_spec.rb
|
316
|
-
- spec/producer/core/recipe/
|
311
|
+
- spec/producer/core/recipe/file_evaluator_spec.rb
|
317
312
|
- spec/producer/core/recipe_spec.rb
|
318
313
|
- spec/producer/core/remote/environment_spec.rb
|
319
314
|
- spec/producer/core/remote/fs_spec.rb
|
320
315
|
- spec/producer/core/remote_spec.rb
|
321
|
-
- spec/producer/core/task/dsl_spec.rb
|
322
316
|
- spec/producer/core/task_spec.rb
|
323
317
|
- spec/producer/core/test_spec.rb
|
324
318
|
- spec/producer/core/testing/mock_remote_spec.rb
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module Producer
|
2
|
-
module Core
|
3
|
-
class Condition
|
4
|
-
class DSL
|
5
|
-
class << self
|
6
|
-
def define_test(keyword, test)
|
7
|
-
{
|
8
|
-
keyword => false,
|
9
|
-
"no_#{keyword}" => true
|
10
|
-
}.each do |kw, negated|
|
11
|
-
define_method(kw) do |*args|
|
12
|
-
if test.respond_to? :call
|
13
|
-
args = [test, *args]
|
14
|
-
klass = Tests::ConditionTest
|
15
|
-
else
|
16
|
-
klass = test
|
17
|
-
end
|
18
|
-
t = klass.new(@env, *args, negated: negated)
|
19
|
-
@tests << t
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
define_test :`, Tests::ShellCommandStatus
|
26
|
-
define_test :sh, Tests::ShellCommandStatus
|
27
|
-
define_test :file_contains, Tests::FileContains
|
28
|
-
define_test :file_eq, Tests::FileEq
|
29
|
-
define_test :env?, Tests::HasEnv
|
30
|
-
define_test :executable?, Tests::HasExecutable
|
31
|
-
define_test :dir?, Tests::HasDir
|
32
|
-
define_test :file?, Tests::HasFile
|
33
|
-
|
34
|
-
attr_reader :block, :env, :tests
|
35
|
-
|
36
|
-
def initialize(env, &block)
|
37
|
-
@env = env
|
38
|
-
@block = block
|
39
|
-
@tests = []
|
40
|
-
end
|
41
|
-
|
42
|
-
def evaluate(*args)
|
43
|
-
instance_exec *args, &@block
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
module Producer
|
2
|
-
module Core
|
3
|
-
class Recipe
|
4
|
-
class DSL
|
5
|
-
class << self
|
6
|
-
def define_macro(name, block)
|
7
|
-
define_method(name) { |*args| task name, *args, &block }
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
attr_reader :env, :code, :block, :tasks
|
12
|
-
|
13
|
-
def initialize(env, code = nil, &block)
|
14
|
-
@env = env
|
15
|
-
@code = code
|
16
|
-
@block = block
|
17
|
-
@tasks = []
|
18
|
-
end
|
19
|
-
|
20
|
-
def evaluate
|
21
|
-
if @code
|
22
|
-
instance_eval @code
|
23
|
-
else
|
24
|
-
instance_eval &@block
|
25
|
-
end
|
26
|
-
self
|
27
|
-
end
|
28
|
-
|
29
|
-
def source(filepath)
|
30
|
-
instance_eval File.read("./#{filepath}.rb"), "#{filepath}.rb"
|
31
|
-
end
|
32
|
-
|
33
|
-
def target(hostname)
|
34
|
-
env.target ||= hostname
|
35
|
-
end
|
36
|
-
|
37
|
-
def task(name, *args, &block)
|
38
|
-
@tasks << Task.evaluate(name, env, *args, &block)
|
39
|
-
end
|
40
|
-
|
41
|
-
def macro(name, &block)
|
42
|
-
define_singleton_method(name) do |*args|
|
43
|
-
task("#{name}", *args, &block)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_macro(name, dsl: Condition::DSL, &block)
|
48
|
-
dsl.define_test(name, block)
|
49
|
-
end
|
50
|
-
|
51
|
-
def set(key, value)
|
52
|
-
env[key] = value
|
53
|
-
end
|
54
|
-
|
55
|
-
def get(key)
|
56
|
-
env[key]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module Producer
|
2
|
-
module Core
|
3
|
-
class Task
|
4
|
-
class DSL
|
5
|
-
class << self
|
6
|
-
def define_action(keyword, klass)
|
7
|
-
define_method(keyword) do |*args|
|
8
|
-
@actions << klass.new(@env, *args)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
define_action :echo, Actions::Echo
|
14
|
-
define_action :sh, Actions::ShellCommand
|
15
|
-
|
16
|
-
define_action :mkdir, Actions::Mkdir
|
17
|
-
|
18
|
-
define_action :file_append, Actions::FileAppend
|
19
|
-
define_action :file_replace_content, Actions::FileReplaceContent
|
20
|
-
define_action :file_write, Actions::FileWriter
|
21
|
-
|
22
|
-
attr_reader :env, :block, :actions
|
23
|
-
|
24
|
-
def initialize(env, &block)
|
25
|
-
@env = env
|
26
|
-
@block = block
|
27
|
-
@actions = []
|
28
|
-
@condition = true
|
29
|
-
end
|
30
|
-
|
31
|
-
def evaluate(*args)
|
32
|
-
instance_exec *args, &@block
|
33
|
-
end
|
34
|
-
|
35
|
-
def condition(&block)
|
36
|
-
@condition = Condition.evaluate(@env, &block) if block
|
37
|
-
@condition
|
38
|
-
end
|
39
|
-
|
40
|
-
def ask(question, choices, prompter: Prompter)
|
41
|
-
prompter.new(env.input, env.output).prompt(question, choices)
|
42
|
-
end
|
43
|
-
|
44
|
-
def get(key)
|
45
|
-
env[key]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Producer::Core
|
4
|
-
class Condition
|
5
|
-
describe DSL do
|
6
|
-
let(:block) { proc { :some_condition_code } }
|
7
|
-
let(:env) { double 'env' }
|
8
|
-
subject(:dsl) { DSL.new(env, &block) }
|
9
|
-
|
10
|
-
%w[
|
11
|
-
`
|
12
|
-
sh
|
13
|
-
file_contains
|
14
|
-
file_eq
|
15
|
-
dir?
|
16
|
-
env?
|
17
|
-
executable?
|
18
|
-
file?
|
19
|
-
].each do |test|
|
20
|
-
it "has `#{test}' test defined" do
|
21
|
-
expect(dsl).to respond_to test.to_sym
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '.define_test' do
|
26
|
-
let(:some_test) { Test }
|
27
|
-
|
28
|
-
before { described_class.define_test(:some_test, some_test) }
|
29
|
-
|
30
|
-
it 'defines a new test keyword' do
|
31
|
-
expect(dsl).to respond_to :some_test
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'defines the negated test' do
|
35
|
-
expect(dsl).to respond_to :no_some_test
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'when a test keyword is called' do
|
39
|
-
it 'registers the test' do
|
40
|
-
expect { dsl.some_test }.to change { dsl.tests.count }.by 1
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'registers the test with current env' do
|
44
|
-
dsl.some_test
|
45
|
-
expect(dsl.tests.last.env).to be env
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'registers the test with given arguments' do
|
49
|
-
dsl.some_test :some, :args
|
50
|
-
expect(dsl.tests.last.arguments).to eq [:some, :args]
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'when given test is callable' do
|
54
|
-
let(:some_test) { proc {} }
|
55
|
-
|
56
|
-
before { dsl.some_test }
|
57
|
-
|
58
|
-
it 'registers a condition test' do
|
59
|
-
expect(dsl.tests.last).to be_a Tests::ConditionTest
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'registers the test with given block' do
|
63
|
-
expect(dsl.tests.last.condition_block).to be some_test
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'registers the test with given arguments' do
|
67
|
-
dsl.some_test :some, :args
|
68
|
-
expect(dsl.tests.last.condition_args).to eq [:some, :args]
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context 'when a negated test keyword is called' do
|
74
|
-
it 'registers a negated test' do
|
75
|
-
dsl.no_some_test
|
76
|
-
expect(dsl.tests.last).to be_negated
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe '#initialize' do
|
82
|
-
it 'assigns the env' do
|
83
|
-
expect(dsl.env).to be env
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'assigns the code' do
|
87
|
-
expect(dsl.block).to be block
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'assigns no test' do
|
91
|
-
expect(dsl.tests).to be_empty
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe '#evaluate' do
|
96
|
-
it 'evaluates its code' do
|
97
|
-
dsl = described_class.new(env) { throw :condition_code }
|
98
|
-
expect { dsl.evaluate }.to throw_symbol :condition_code
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'returns the value returned by the assigned block' do
|
102
|
-
expect(dsl.evaluate).to eq block.call
|
103
|
-
end
|
104
|
-
|
105
|
-
context 'when arguments are given' do
|
106
|
-
let(:block) { proc { |e| throw e } }
|
107
|
-
|
108
|
-
it 'passes arguments as block parameters' do
|
109
|
-
expect { dsl.evaluate :some_argument }
|
110
|
-
.to throw_symbol :some_argument
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|