yuyi 1.0.8 → 1.1.3
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/.new +1 -1
- data/.ruby-version +1 -0
- data/Gemfile +7 -2
- data/Gemfile.lock +16 -21
- data/Guardfile +1 -1
- data/README.md +41 -24
- data/Rakefile +38 -0
- data/bin/yuyi +9 -1
- data/lib/yuyi/cli.rb +32 -363
- data/lib/yuyi/core.rb +4 -0
- data/lib/yuyi/dsl.rb +131 -0
- data/lib/yuyi/menu.rb +174 -166
- data/lib/yuyi/roll.rb +95 -140
- data/lib/yuyi/source.rb +4 -3
- data/lib/yuyi/ui.rb +103 -0
- data/lib/yuyi.rb +17 -2
- data/spec/fixtures/menu.yaml +3 -2
- data/spec/fixtures/menu2.yaml +5 -2
- data/spec/fixtures/roll_dir/{nested/foo_roll.rb → foo_roll.rb} +0 -0
- data/spec/fixtures/roll_dir/foo_roll_model.rb +2 -0
- data/spec/fixtures/roll_dir/nested/bar_roll.rb +1 -1
- data/spec/fixtures/roll_zip.zip +0 -0
- data/spec/lib/yuyi/cli_spec.rb +11 -310
- data/spec/lib/yuyi/core_spec.rb +1 -1
- data/spec/lib/yuyi/dsl_spec.rb +135 -0
- data/spec/lib/yuyi/menu_spec.rb +177 -117
- data/spec/lib/yuyi/roll_spec.rb +38 -227
- data/spec/lib/yuyi/source_spec.rb +6 -2
- data/spec/lib/yuyi/ui_spec.rb +36 -0
- data/spec/roll_validator.rb +51 -0
- data/spec/spec_helper.rb +2 -0
- data/yuyi_menu +8 -0
- metadata +36 -10
- data/bin/install +0 -42
data/spec/lib/yuyi/menu_spec.rb
CHANGED
@@ -2,117 +2,219 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Yuyi::Menu do
|
4
4
|
before do
|
5
|
-
|
6
|
-
Yuyi::Menu.send :
|
7
|
-
end
|
5
|
+
# reset current menu instance
|
6
|
+
Yuyi::Menu.send :class_variable_set, :'@@menu', nil
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
Yuyi::Menu.new 'spec/fixtures/menu.yaml'
|
13
|
-
end
|
8
|
+
allow_any_instance_of(Yuyi::Menu).to receive(:load_from_file)
|
9
|
+
allow_any_instance_of(Yuyi::Menu).to receive(:set_sources)
|
10
|
+
allow_any_instance_of(Yuyi::Menu).to receive(:set_rolls)
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
12
|
+
@menu = Yuyi::Menu.new 'spec/fixtures/menu.yaml'
|
13
|
+
end
|
18
14
|
|
19
|
-
|
20
|
-
|
15
|
+
# CLASS METHODS
|
16
|
+
#
|
17
|
+
describe 'class methods' do
|
18
|
+
describe '.add_roll' do
|
19
|
+
before do
|
20
|
+
class MenuAddRollRoll; end
|
21
|
+
Yuyi::Menu.add_roll :menu_add_roll_roll, MenuAddRollRoll
|
21
22
|
end
|
22
23
|
|
23
|
-
it 'should
|
24
|
-
expect(
|
25
|
-
expect(Yuyi::Menu.object[:sources][1]).to eq({ :yuyi => 'spec/fixtures/roll_zip.zip' })
|
26
|
-
expect(Yuyi::Menu.object[:rolls][:foo_roll]).to eq({ :foo => 'bar' })
|
24
|
+
it 'should add a roll instance' do
|
25
|
+
expect(@menu.instance_var(:rolls)[:menu_add_roll_roll]).to be_a MenuAddRollRoll
|
27
26
|
end
|
28
27
|
end
|
28
|
+
end
|
29
29
|
|
30
|
-
|
30
|
+
# INSTANCE METHODS
|
31
|
+
#
|
32
|
+
describe 'instance methods' do
|
33
|
+
describe '#load_from_file' do
|
31
34
|
before do
|
32
|
-
|
33
|
-
|
35
|
+
# reset yaml var
|
36
|
+
@menu.send :instance_variable_set, :'@yaml', nil
|
34
37
|
|
35
|
-
|
36
|
-
|
38
|
+
allow(@menu).to receive(:load_from_file).and_call_original
|
39
|
+
allow(@menu).to receive(:get_menu_path)
|
37
40
|
end
|
38
41
|
|
39
|
-
|
40
|
-
|
42
|
+
after do
|
43
|
+
allow(@menu).to receive(:get_menu_path).and_call_original
|
41
44
|
end
|
42
|
-
end
|
43
|
-
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
context 'when the path is invalid' do
|
47
|
+
before do
|
48
|
+
@menu.send :load_from_file, 'foo'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should not set the yaml variable' do
|
52
|
+
expect(@menu.instance_var(:yaml)).to be nil
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should not set the menu_path variable' do
|
56
|
+
expect(@menu.instance_var(:menu_path)).to be nil
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should call #get_menu_path' do
|
60
|
+
expect(@menu).to have_received(:get_menu_path)
|
61
|
+
end
|
62
|
+
end
|
49
63
|
|
50
|
-
|
51
|
-
context 'with a local file' do
|
64
|
+
context 'when the path is local' do
|
52
65
|
before do
|
53
|
-
|
66
|
+
@menu.send :load_from_file, 'spec/fixtures/menu.yaml'
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should set the yaml variable' do
|
70
|
+
expect(@menu.instance_var(:yaml)).to be_a Hash
|
54
71
|
end
|
55
72
|
|
56
|
-
it 'should
|
57
|
-
expect(
|
73
|
+
it 'should set the yaml variable' do
|
74
|
+
expect(@menu.instance_var(:menu_path)).to be_a String
|
58
75
|
end
|
59
76
|
end
|
60
77
|
|
61
|
-
context '
|
78
|
+
context 'when the path is remote' do
|
62
79
|
before do
|
63
|
-
|
64
|
-
Yuyi::
|
80
|
+
@tmp_dir = Dir.mktmpdir
|
81
|
+
stub_const 'Yuyi::DEFAULT_MENU', File.join(@tmp_dir, 'yuyi_menu')
|
82
|
+
remote_file = 'file://' << File.join(File.dirname(__FILE__), '../../fixtures/menu.yaml')
|
83
|
+
@menu.send :load_from_file, remote_file
|
65
84
|
end
|
66
85
|
|
67
86
|
after do
|
68
|
-
|
87
|
+
FileUtils.rm File.join(@tmp_dir, 'yuyi_menu_remote')
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should set the yaml variable' do
|
91
|
+
expect(@menu.instance_var(:yaml)).to be_a Hash
|
69
92
|
end
|
70
93
|
|
71
|
-
it 'should
|
72
|
-
expect(
|
94
|
+
it 'should set the yaml variable' do
|
95
|
+
expect(@menu.instance_var(:menu_path)).to be_a String
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should create a _remote local menu file' do
|
99
|
+
expect(File.exist?(File.join(@tmp_dir, 'yuyi_menu_remote'))).to be true
|
73
100
|
end
|
74
101
|
end
|
75
102
|
end
|
76
103
|
|
77
|
-
describe '
|
104
|
+
describe '#get_menu_path' do
|
78
105
|
before do
|
79
|
-
|
80
|
-
|
106
|
+
tmp_dir = Dir.mktmpdir
|
107
|
+
FileUtils.cp File.join(File.dirname(__FILE__), '../../fixtures/menu.yaml'), tmp_dir
|
108
|
+
stub_const 'Yuyi::DEFAULT_MENU', File.join(tmp_dir, 'menu.yaml')
|
109
|
+
@menu.send :instance_variable_set, :'@yaml', nil
|
110
|
+
|
111
|
+
allow(Readline).to receive(:readline).and_return('foo', 'bar', '')
|
112
|
+
allow(@menu).to receive(:load_from_file).and_call_original
|
81
113
|
end
|
82
114
|
|
83
|
-
|
84
|
-
|
115
|
+
after do
|
116
|
+
allow(Readline).to receive(:readline).and_call_original
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should prompt the user to enter a menu path' do
|
120
|
+
expect(@menu).to receive(:load_from_file).exactly(3).times
|
121
|
+
@menu.send :get_menu_path
|
85
122
|
end
|
86
123
|
end
|
87
124
|
|
88
125
|
describe '#set_sources' do
|
89
126
|
before do
|
90
|
-
Yuyi::
|
127
|
+
allow(Yuyi::Source).to receive(:new)
|
128
|
+
allow(@menu).to receive(:set_sources).and_call_original
|
91
129
|
|
92
|
-
|
93
|
-
|
130
|
+
@menu.send :instance_variable_set, :'@yaml', { :sources => { :foo => 'bar' }}
|
131
|
+
@menu.send :set_sources
|
132
|
+
end
|
94
133
|
|
95
|
-
|
134
|
+
after do
|
135
|
+
allow(Yuyi::Source).to receive(:new).and_call_original
|
96
136
|
end
|
97
137
|
|
98
|
-
it 'should
|
99
|
-
expect(Yuyi::
|
100
|
-
|
138
|
+
it 'should create a source object from the menu' do
|
139
|
+
expect(Yuyi::Source).to have_received(:new).with :foo, 'bar'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe '#set_rolls' do
|
144
|
+
before do
|
145
|
+
allow(@menu).to receive(:set_rolls).and_call_original
|
146
|
+
allow(@menu).to receive(:find_roll)
|
147
|
+
|
148
|
+
@menu.send :instance_variable_set, :'@yaml', { :rolls => { :foo_roll => {}}}
|
149
|
+
@menu.send :set_rolls
|
150
|
+
end
|
151
|
+
|
152
|
+
after do
|
153
|
+
allow(@menu).to receive(:find_roll).and_call_original
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'should require rolls' do
|
157
|
+
expect(@menu).to have_received(:find_roll)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe '#order' do
|
162
|
+
before do
|
163
|
+
class MenuOrderOne; end
|
164
|
+
class MenuOrderTwo; end
|
165
|
+
allow(MenuOrderOne).to receive :appetizers
|
166
|
+
allow(MenuOrderTwo).to receive :appetizers
|
167
|
+
allow(MenuOrderOne).to receive :entree
|
168
|
+
allow(MenuOrderTwo).to receive :entree
|
169
|
+
allow(MenuOrderOne).to receive :dessert
|
170
|
+
allow(MenuOrderTwo).to receive :dessert
|
171
|
+
|
172
|
+
allow(@menu).to receive(:sorted_rolls).and_return([:menu_order_one, :menu_order_two])
|
173
|
+
@menu.instance_var :rolls, { :menu_order_one => MenuOrderOne, :menu_order_two => MenuOrderTwo }
|
174
|
+
|
175
|
+
@menu.send :order
|
176
|
+
end
|
177
|
+
|
178
|
+
after do
|
179
|
+
allow(@menu).to receive(:sorted_rolls).and_call_original
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should initialize a roll with the roll options' do
|
183
|
+
expect(MenuOrderOne).to have_received(:appetizers).ordered
|
184
|
+
expect(MenuOrderTwo).to have_received(:appetizers).ordered
|
185
|
+
expect(MenuOrderOne).to have_received(:entree).ordered
|
186
|
+
expect(MenuOrderTwo).to have_received(:entree).ordered
|
187
|
+
expect(MenuOrderOne).to have_received(:dessert).ordered
|
188
|
+
expect(MenuOrderTwo).to have_received(:dessert).ordered
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe '#sorted_rolls' do
|
193
|
+
before do
|
194
|
+
@menu.instance_var :rolls, {
|
195
|
+
:dependency_roll => OpenStruct.new({ :dependencies => ['foo', 'bar'] }),
|
196
|
+
:foo => OpenStruct.new({ :dependencies => [] }),
|
197
|
+
:bar => OpenStruct.new({ :dependencies => [] })
|
198
|
+
}
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should add the roll to the class var' do
|
202
|
+
expect(@menu.send(:sorted_rolls).sort_by { |sym| sym.to_s }).to eq([:bar, :dependency_roll, :foo])
|
101
203
|
end
|
102
204
|
end
|
103
205
|
|
104
206
|
describe '#find_roll' do
|
105
207
|
before do
|
106
|
-
allow(
|
208
|
+
allow(@menu).to receive :require_roll
|
107
209
|
end
|
108
210
|
|
109
211
|
context 'when a source is specified' do
|
110
212
|
before do
|
111
|
-
|
213
|
+
@menu.send :find_roll, :foo_roll, { :source => 'foo_source' }
|
112
214
|
end
|
113
215
|
|
114
216
|
it 'should require the specific roll' do
|
115
|
-
expect(
|
217
|
+
expect(@menu).to have_received(:require_roll).once.with(:foo_roll, 'foo_source/foo_roll')
|
116
218
|
end
|
117
219
|
end
|
118
220
|
|
@@ -120,88 +222,46 @@ describe Yuyi::Menu do
|
|
120
222
|
before do
|
121
223
|
class TestSourceA; end
|
122
224
|
class TestSourceB; end
|
123
|
-
allow(TestSourceA).to receive(:
|
124
|
-
allow(TestSourceB).to receive(:
|
225
|
+
allow(TestSourceA).to receive(:rolls).and_return({ :foo_roll => 'foo_roll' })
|
226
|
+
allow(TestSourceB).to receive(:rolls).and_return({ :bar_roll => 'bar_roll' })
|
125
227
|
|
126
|
-
|
228
|
+
@menu.var :sources, [TestSourceA, TestSourceB]
|
127
229
|
end
|
128
230
|
|
129
231
|
it 'should require the first roll found' do
|
130
|
-
expect(
|
131
|
-
|
232
|
+
expect(@menu).to receive(:require_roll).once.with(:bar_roll, 'bar_roll')
|
233
|
+
@menu.send :find_roll, :bar_roll
|
132
234
|
end
|
133
235
|
end
|
134
236
|
|
135
237
|
context 'when no roll is found' do
|
136
238
|
before do
|
137
239
|
class TestSource; end
|
138
|
-
allow(TestSource).to receive(:
|
240
|
+
allow(TestSource).to receive(:rolls).and_return({})
|
139
241
|
|
140
|
-
|
242
|
+
@menu.var :sources, [TestSource]
|
141
243
|
end
|
142
244
|
|
143
245
|
it 'should not attempt to require a roll' do
|
144
|
-
expect(
|
145
|
-
|
246
|
+
expect(@menu).to_not receive(:require_roll)
|
247
|
+
@menu.send :find_roll, :no_roll
|
146
248
|
end
|
147
249
|
end
|
148
250
|
end
|
149
251
|
|
150
|
-
describe '#
|
252
|
+
describe '#options' do
|
151
253
|
before do
|
152
|
-
|
254
|
+
@menu.instance_var :yaml, {
|
255
|
+
:rolls => {
|
256
|
+
:foo_roll => {
|
257
|
+
:foo => :bar
|
258
|
+
}
|
259
|
+
}
|
260
|
+
}
|
153
261
|
end
|
154
262
|
|
155
|
-
it 'should return
|
156
|
-
expect(
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
describe '#sorted_rolls' do
|
161
|
-
before do
|
162
|
-
class DependencyRoll
|
163
|
-
def dependencies; ['foo', 'bar']; end
|
164
|
-
end
|
165
|
-
class EmptyDependencyRoll
|
166
|
-
def dependencies; []; end
|
167
|
-
end
|
168
|
-
allow(Yuyi::Menu.instance).to receive(:rolls).and_return({ :dependency_roll => DependencyRoll.new, :foo => EmptyDependencyRoll.new, :bar => EmptyDependencyRoll.new })
|
169
|
-
end
|
170
|
-
|
171
|
-
it 'should add the roll to the class var' do
|
172
|
-
expect(Yuyi::Menu.instance.send(:sorted_rolls).sort_by { |sym| sym.to_s }).to eq([:bar, :dependency_roll, :foo])
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe '#order_rolls' do
|
177
|
-
before do
|
178
|
-
class MenuOrderRollsOne; end
|
179
|
-
class MenuOrderRollsTwo; end
|
180
|
-
allow(MenuOrderRollsOne).to receive :appetizers
|
181
|
-
allow(MenuOrderRollsTwo).to receive :appetizers
|
182
|
-
allow(MenuOrderRollsOne).to receive :entree
|
183
|
-
allow(MenuOrderRollsTwo).to receive :entree
|
184
|
-
allow(MenuOrderRollsOne).to receive :dessert
|
185
|
-
allow(MenuOrderRollsTwo).to receive :dessert
|
186
|
-
|
187
|
-
allow(Yuyi::Menu.instance).to receive(:sorted_rolls).and_return([:menu_order_rolls_one, :menu_order_rolls_two])
|
188
|
-
allow(Yuyi::Menu.instance).to receive(:rolls).and_return({ :menu_order_rolls_one => MenuOrderRollsOne, :menu_order_rolls_two => MenuOrderRollsTwo })
|
189
|
-
|
190
|
-
Yuyi::Menu.instance.send :order_rolls
|
191
|
-
end
|
192
|
-
|
193
|
-
after do
|
194
|
-
allow(Yuyi::Menu.instance).to receive(:sorted_rolls).and_call_original
|
195
|
-
allow(Yuyi::Menu.instance).to receive(:rolls).and_call_original
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'should initialize a roll with the roll options' do
|
199
|
-
expect(MenuOrderRollsOne).to have_received(:appetizers).ordered
|
200
|
-
expect(MenuOrderRollsTwo).to have_received(:appetizers).ordered
|
201
|
-
expect(MenuOrderRollsOne).to have_received(:entree).ordered
|
202
|
-
expect(MenuOrderRollsTwo).to have_received(:entree).ordered
|
203
|
-
expect(MenuOrderRollsOne).to have_received(:dessert).ordered
|
204
|
-
expect(MenuOrderRollsTwo).to have_received(:dessert).ordered
|
263
|
+
it 'should return roll options' do
|
264
|
+
expect(@menu.options(:foo_roll)[:foo]).to eq :bar
|
205
265
|
end
|
206
266
|
end
|
207
267
|
end
|
data/spec/lib/yuyi/roll_spec.rb
CHANGED
@@ -1,41 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Yuyi::Roll do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
allow(Yuyi::Menu).to receive(:on_the_menu?).and_return false
|
4
|
+
describe '.dependencies' do
|
5
|
+
before do
|
6
|
+
allow(Yuyi::Menu).to receive(:find_roll)
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
install { :install }
|
13
|
-
post_install { :post_install }
|
14
|
-
uninstall { :uninstall }
|
15
|
-
upgrade { :upgrade }
|
16
|
-
installed? { :installed? }
|
17
|
-
dependencies :foo
|
18
|
-
options({
|
19
|
-
:foo => {
|
20
|
-
:description => 'Foo.',
|
21
|
-
:example => 'foo example',
|
22
|
-
:default => 'foo default',
|
23
|
-
:required => true
|
24
|
-
},
|
25
|
-
:bar => {
|
26
|
-
:description => 'Bar.',
|
27
|
-
:example => 'bar example',
|
28
|
-
:default => 'bar default'
|
29
|
-
}
|
30
|
-
})
|
9
|
+
after do
|
10
|
+
allow(Yuyi::Menu).to receive(:find_roll).and_call_original
|
31
11
|
end
|
32
|
-
end
|
33
12
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
13
|
+
it 'should call find dependency rolls' do
|
14
|
+
expect(Yuyi::Menu).to receive(:find_roll).with :foo
|
15
|
+
expect(Yuyi::Menu).to receive(:find_roll).with :bar
|
16
|
+
Yuyi::Roll.dependencies :foo, :bar
|
17
|
+
end
|
39
18
|
end
|
40
19
|
|
41
20
|
describe '.class_to_title' do
|
@@ -51,223 +30,55 @@ describe Yuyi::Roll do
|
|
51
30
|
end
|
52
31
|
|
53
32
|
context 'when inherited' do
|
54
|
-
it 'should add the roll to the menu' do
|
55
|
-
allow(Yuyi::Menu).to receive :add_roll
|
56
|
-
|
57
|
-
class Yuyi::TestInheritRoll < Yuyi::Roll
|
58
|
-
install {}
|
59
|
-
uninstall {}
|
60
|
-
upgrade {}
|
61
|
-
installed? {}
|
62
|
-
end
|
63
|
-
|
64
|
-
expect(Yuyi::Menu).to have_received(:add_roll).with :roll_spec, Yuyi::TestInheritRoll
|
65
|
-
end
|
66
|
-
|
67
|
-
# DSL Methods
|
68
|
-
#
|
69
|
-
|
70
|
-
it 'should add dependencies' do
|
71
|
-
expect(Yuyi::Menu).to have_received(:find_roll).with :foo
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'should create a title' do
|
75
|
-
expect(Yuyi::TestRoll.title).to eq 'Test Roll'
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'should create a file name' do
|
79
|
-
expect(Yuyi::TestRoll.file_name).to eq :roll_spec
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should respond to .pre_install' do
|
83
|
-
expect(Yuyi::TestRoll.pre_install).to be_a Proc
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'should respond to .install' do
|
87
|
-
expect(Yuyi::TestRoll.install).to be_a Proc
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should respond to .post_install' do
|
91
|
-
expect(Yuyi::TestRoll.post_install).to be_a Proc
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should respond to .uninstall' do
|
95
|
-
expect(Yuyi::TestRoll.uninstall).to be_a Proc
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'should respond to .upgrade' do
|
99
|
-
expect(Yuyi::TestRoll.upgrade).to be_a Proc
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'should respond to .installed?' do
|
103
|
-
expect(Yuyi::TestRoll.installed?).to be_a Proc
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'should return .dependencies' do
|
107
|
-
expect(Yuyi::TestRoll.dependencies).to eq([:foo])
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'should return .options' do
|
111
|
-
expect(Yuyi::TestRoll.options[:foo][:default]).to eq 'foo default'
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
context 'when initialized' do
|
116
33
|
before do
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'should return the title' do
|
121
|
-
expect(@test_roll.title).to eq 'Test Roll'
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'should return the file_name' do
|
125
|
-
expect(@test_roll.file_name).to eq :roll_spec
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'should add dependencies' do
|
129
|
-
expect(@test_roll.dependencies).to eq([:foo])
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'should return the pre_install results' do
|
133
|
-
expect(@test_roll.send(:pre_install)).to eq :pre_install
|
34
|
+
allow(Yuyi::Menu).to receive(:add_roll)
|
134
35
|
end
|
135
36
|
|
136
|
-
|
137
|
-
|
37
|
+
after do
|
38
|
+
allow(Yuyi::Menu).to receive(:add_roll).and_call_original
|
138
39
|
end
|
139
40
|
|
140
|
-
it 'should
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
it 'should return the uninstall results' do
|
145
|
-
expect(@test_roll.send(:uninstall)).to eq :uninstall
|
41
|
+
it 'should add the roll to the menu' do
|
42
|
+
class RollSpecInheritedRoll < Yuyi::Roll; end
|
43
|
+
expect(Yuyi::Menu).to have_received(:add_roll).with :roll_spec, RollSpecInheritedRoll
|
146
44
|
end
|
147
45
|
|
148
|
-
it 'should
|
149
|
-
|
46
|
+
it 'should respond to title' do
|
47
|
+
class RollSpecTitle < Yuyi::Roll; end
|
48
|
+
expect(RollSpecTitle.title).to eq 'Roll Spec Title'
|
150
49
|
end
|
151
50
|
|
152
|
-
it 'should
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
it 'should return options' do
|
157
|
-
expect(@test_roll.options).to eq({
|
158
|
-
:foo => 'menu option',
|
159
|
-
:bar => 'bar default'
|
160
|
-
})
|
161
|
-
|
162
|
-
expect(@test_roll.option_defs).to eq({
|
163
|
-
:foo => {
|
164
|
-
:description => 'Foo.',
|
165
|
-
:example => 'foo example',
|
166
|
-
:default => 'foo default',
|
167
|
-
:required => true
|
168
|
-
},
|
169
|
-
:bar => {
|
170
|
-
:description => 'Bar.',
|
171
|
-
:example => 'bar example',
|
172
|
-
:default => 'bar default'
|
173
|
-
}
|
174
|
-
})
|
51
|
+
it 'should respond to file_name' do
|
52
|
+
class RollSpecFileName < Yuyi::Roll; end
|
53
|
+
expect(RollSpecFileName.file_name).to eq :roll_spec
|
175
54
|
end
|
176
55
|
end
|
177
56
|
|
178
|
-
|
57
|
+
describe 'instance' do
|
179
58
|
before do
|
180
|
-
|
181
|
-
allow(
|
182
|
-
allow(@roll).to receive(:uninstall)
|
183
|
-
allow(@roll).to receive(:upgrade)
|
184
|
-
end
|
59
|
+
allow(Yuyi::Menu).to receive(:add_roll)
|
60
|
+
allow(Yuyi::Menu).to receive(:find_roll)
|
185
61
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
62
|
+
class RollSpecInstance < Yuyi::Roll
|
63
|
+
dependencies :foo, :bar
|
64
|
+
installed? { false }
|
65
|
+
pre_install { 'Pre Install' }
|
190
66
|
end
|
191
67
|
|
192
|
-
|
193
|
-
expect(@roll).to have_received :install
|
194
|
-
expect(@roll).to_not have_received :uninstall
|
195
|
-
expect(@roll).to_not have_received :upgrade
|
196
|
-
end
|
68
|
+
@roll = RollSpecInstance.new
|
197
69
|
end
|
198
70
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
end
|
203
|
-
|
204
|
-
context 'when uninstall option is set' do
|
205
|
-
before do
|
206
|
-
allow(Yuyi::Menu).to receive(:options).and_return({ :uninstall => true })
|
207
|
-
@roll.send :order
|
208
|
-
end
|
209
|
-
|
210
|
-
it 'should call uninstall' do
|
211
|
-
expect(@roll).to_not have_received :install
|
212
|
-
expect(@roll).to have_received :uninstall
|
213
|
-
expect(@roll).to_not have_received :upgrade
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
context 'when uninstall option is not set & upgrade is true' do
|
218
|
-
before do
|
219
|
-
allow(@roll).to receive(:upgrade?).and_return true
|
220
|
-
@roll.send :order
|
221
|
-
end
|
222
|
-
|
223
|
-
it 'should call upgrade' do
|
224
|
-
expect(@roll).to_not have_received :install
|
225
|
-
expect(@roll).to_not have_received :uninstall
|
226
|
-
expect(@roll).to have_received :upgrade
|
227
|
-
end
|
228
|
-
end
|
71
|
+
after do
|
72
|
+
allow(Yuyi::Menu).to receive(:add_roll).and_call_original
|
73
|
+
allow(Yuyi::Menu).to receive(:find_roll).and_call_original
|
229
74
|
end
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
describe 'Yuyi::RollModel' do
|
234
|
-
before do
|
235
|
-
allow(Yuyi::Menu).to receive(:add_roll)
|
236
|
-
|
237
|
-
class Yuyi::FooRollModel < Yuyi::Roll
|
238
|
-
def self.inherited klass; add_roll klass, caller; end
|
239
|
-
def self.foo_name name
|
240
|
-
install { name }
|
241
|
-
installed? { false }
|
242
|
-
end
|
243
75
|
|
76
|
+
it 'should respond to pre_install' do
|
77
|
+
expect(@roll.pre_install).to eq 'Pre Install'
|
244
78
|
end
|
245
79
|
|
246
|
-
|
247
|
-
|
248
|
-
installed? { true }
|
80
|
+
it 'should respond to dependencies' do
|
81
|
+
expect(@roll.dependencies).to eq [ :foo, :bar ]
|
249
82
|
end
|
250
83
|
end
|
251
|
-
|
252
|
-
after do
|
253
|
-
allow(Yuyi::Menu).to receive(:add_roll).and_call_original
|
254
|
-
end
|
255
|
-
|
256
|
-
it 'should not add the roll model' do
|
257
|
-
class Yuyi::BarRollModel < Yuyi::Roll; end
|
258
|
-
expect(Yuyi::Menu).to_not have_received(:add_roll).with :roll_spec, Yuyi::BarRollModel
|
259
|
-
end
|
260
|
-
|
261
|
-
it 'should add the inherited roll' do
|
262
|
-
class Yuyi::FooInheritedRoll < Yuyi::FooRollModel; end
|
263
|
-
expect(Yuyi::Menu).to have_received(:add_roll).with :roll_spec, Yuyi::FooInheritedRoll
|
264
|
-
end
|
265
|
-
|
266
|
-
it 'should use the roll model methods' do
|
267
|
-
expect(Yuyi::FooModelRoll.new.send(:install)).to eq 'Foo Name'
|
268
|
-
end
|
269
|
-
|
270
|
-
it 'should prefer the roll methods over the model methods' do
|
271
|
-
expect(Yuyi::FooModelRoll.new.send(:installed?)).to be true
|
272
|
-
end
|
273
84
|
end
|