producer-core 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,140 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Producer::Core
|
4
|
-
class Recipe
|
5
|
-
describe DSL do
|
6
|
-
include FixturesHelpers
|
7
|
-
|
8
|
-
let(:code) { proc { :some_recipe_code } }
|
9
|
-
let(:env) { Env.new }
|
10
|
-
subject(:dsl) { DSL.new(env, &code) }
|
11
|
-
|
12
|
-
describe '#initialize' do
|
13
|
-
it 'assigns the given env' do
|
14
|
-
expect(dsl.env).to be env
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'assigns no task' do
|
18
|
-
expect(dsl.tasks).to be_empty
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when a string of code is given as argument' do
|
22
|
-
let(:code) { 'some_code' }
|
23
|
-
subject(:dsl) { described_class.new(env, code) }
|
24
|
-
|
25
|
-
it 'assigns the string of code' do
|
26
|
-
expect(dsl.code).to eq code
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'when a code block is given as argument' do
|
31
|
-
it 'assigns the code block' do
|
32
|
-
expect(dsl.block).to be code
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '#tasks' do
|
38
|
-
let(:code) { proc { task(:some_task) {} } }
|
39
|
-
|
40
|
-
it 'returns registered tasks' do
|
41
|
-
dsl.evaluate
|
42
|
-
expect(dsl.tasks[0].name).to eq :some_task
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#evaluate' do
|
47
|
-
it 'evaluates its code' do
|
48
|
-
dsl = described_class.new(env) { throw :recipe_code }
|
49
|
-
expect { dsl.evaluate }.to throw_symbol :recipe_code
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'returns itself' do
|
53
|
-
expect(dsl.evaluate).to eq dsl
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe '#source' do
|
58
|
-
let(:filepath) { fixture_path_for 'recipes/throw' }
|
59
|
-
|
60
|
-
it 'sources the recipe given as argument' do
|
61
|
-
expect { dsl.source filepath }.to throw_symbol :recipe_code
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe '#target' do
|
66
|
-
let(:host) { 'some_host.example' }
|
67
|
-
|
68
|
-
context 'when env has no assigned target' do
|
69
|
-
it 'registers the target host in the env' do
|
70
|
-
dsl.target host
|
71
|
-
expect(env.target).to eq host
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'when env has an assigned target' do
|
76
|
-
before { env.target = 'already_assigned_host.example' }
|
77
|
-
|
78
|
-
it 'does not change env target' do
|
79
|
-
expect { dsl.target host }.not_to change { env.target }
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe '#task' do
|
85
|
-
it 'registers a new evaluated task' do
|
86
|
-
expect { dsl.task(:some_task) { :some_task_code } }
|
87
|
-
.to change { dsl.tasks.count }.by 1
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe '#macro' do
|
92
|
-
it 'defines the new recipe keyword' do
|
93
|
-
dsl.macro :hello
|
94
|
-
expect(dsl).to respond_to(:hello)
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'when a defined macro is called' do
|
98
|
-
before { dsl.macro(:hello) { :some_macro_code } }
|
99
|
-
|
100
|
-
it 'registers the new task' do
|
101
|
-
expect { dsl.hello }.to change { dsl.tasks.count }.by 1
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context 'when a defined macro is called with arguments' do
|
106
|
-
before { dsl.macro(:hello) { |a, b| echo a, b } }
|
107
|
-
|
108
|
-
it 'evaluates task code with arguments' do
|
109
|
-
dsl.hello :some, :args
|
110
|
-
expect(dsl.tasks.first.actions.first.arguments).to eq [:some, :args]
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe '#test_macro' do
|
116
|
-
it 'defines the new test' do
|
117
|
-
condition_dsl = double 'condition dsl'
|
118
|
-
test_block = proc {}
|
119
|
-
expect(condition_dsl)
|
120
|
-
.to receive(:define_test).with(:some_test, test_block)
|
121
|
-
dsl.test_macro(:some_test, dsl: condition_dsl, &test_block)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe '#set' do
|
126
|
-
it 'registers a key/value pair in env registry' do
|
127
|
-
dsl.set :some_key, :some_value
|
128
|
-
expect(env[:some_key]).to eq :some_value
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
describe '#get' do
|
133
|
-
it 'fetches a value from the registry at given index' do
|
134
|
-
dsl.set :some_key, :some_value
|
135
|
-
expect(dsl.get :some_key).to eq :some_value
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
@@ -1,123 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Producer::Core
|
4
|
-
class Task
|
5
|
-
describe DSL do
|
6
|
-
let(:block) { proc {} }
|
7
|
-
let(:env) { Env.new }
|
8
|
-
subject(:dsl) { DSL.new(env, &block) }
|
9
|
-
|
10
|
-
%w[
|
11
|
-
echo
|
12
|
-
sh
|
13
|
-
mkdir
|
14
|
-
file_append
|
15
|
-
file_replace_content
|
16
|
-
file_write
|
17
|
-
].each do |action|
|
18
|
-
it "has `#{action}' action defined" do
|
19
|
-
expect(dsl).to respond_to action.to_sym
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe '.define_action' do
|
24
|
-
let(:some_action_class) { Class.new(Action) }
|
25
|
-
|
26
|
-
before { described_class.define_action(:some_action, some_action_class) }
|
27
|
-
|
28
|
-
it 'defines a new action keyword' do
|
29
|
-
expect(dsl).to respond_to :some_action
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when an action keyword is called' do
|
33
|
-
it 'registers the action' do
|
34
|
-
expect { dsl.some_action }.to change { dsl.actions.count }.by 1
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'registers the action with current env' do
|
38
|
-
dsl.some_action
|
39
|
-
expect(dsl.actions.first.env).to be env
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'registers the action with given arguments' do
|
43
|
-
dsl.some_action :some, :args
|
44
|
-
expect(dsl.actions.first.arguments).to eq [:some, :args]
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#initialize' do
|
50
|
-
it 'assigns the given env' do
|
51
|
-
expect(dsl.env).to be env
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'assigns the given block' do
|
55
|
-
expect(dsl.block).to be block
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'assigns no action' do
|
59
|
-
expect(dsl.actions).to be_empty
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'assigns true as the condition' do
|
63
|
-
expect(dsl.condition).to be true
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe '#evaluate' do
|
68
|
-
let(:block) { proc { throw :task_code } }
|
69
|
-
|
70
|
-
it 'evaluates its code' do
|
71
|
-
expect { dsl.evaluate }
|
72
|
-
.to throw_symbol :task_code
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'when arguments are given' do
|
76
|
-
let(:block) { proc { |e| throw e } }
|
77
|
-
|
78
|
-
it 'passes arguments as block parameters' do
|
79
|
-
expect { dsl.evaluate :some_argument }
|
80
|
-
.to throw_symbol :some_argument
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe '#condition' do
|
86
|
-
context 'when a block is given' do
|
87
|
-
it 'assigns a new evaluated condition' do
|
88
|
-
dsl.condition { :some_return_value }
|
89
|
-
expect(dsl.condition.return_value).to eq :some_return_value
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe '#ask' do
|
95
|
-
let(:question) { 'Which letter?' }
|
96
|
-
let(:choices) { [[:a, ?A], [:b, ?B]] }
|
97
|
-
let(:prompter_class) { double('prompter class').as_null_object }
|
98
|
-
subject(:ask) { dsl.ask question, choices,
|
99
|
-
prompter: prompter_class }
|
100
|
-
|
101
|
-
it 'builds a prompter' do
|
102
|
-
expect(prompter_class).to receive(:new).with(env.input, env.output)
|
103
|
-
ask
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'prompts and returns the choice' do
|
107
|
-
prompter = double 'prompter'
|
108
|
-
allow(prompter_class).to receive(:new) { prompter }
|
109
|
-
allow(prompter).to receive(:prompt) { :choice }
|
110
|
-
expect(ask).to eq :choice
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe '#get' do
|
115
|
-
let(:env) { Env.new(registry: { some_key: :some_value }) }
|
116
|
-
|
117
|
-
it 'fetches a value from the registry at given index' do
|
118
|
-
expect(dsl.get :some_key).to eq :some_value
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|