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/cli_spec.rb
CHANGED
@@ -1,331 +1,32 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
|
3
|
-
options = Yuyi::Cli::CLI_OPTIONS.keys
|
2
|
+
require 'yuyi/cli'
|
4
3
|
|
5
4
|
describe Yuyi::Cli do
|
6
|
-
before do
|
7
|
-
class CliTest; extend Yuyi::Cli; end
|
8
|
-
allow(CliTest).to receive(:say)
|
9
|
-
CliTest.send(:instance_variable_set, :'@path', nil)
|
10
|
-
end
|
11
|
-
|
12
|
-
describe 'CLI_OPTIONS' do
|
13
|
-
it 'should have options with a unique first character' do
|
14
|
-
flags = options.map{ |option| option.to_s.chars.first }
|
15
|
-
|
16
|
-
expect(flags.uniq.length).to eq options.length
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '#init' do
|
21
|
-
context 'without arguments' do
|
22
|
-
before do
|
23
|
-
allow(CliTest).to receive :start
|
24
|
-
CliTest.init []
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should call start' do
|
28
|
-
expect(CliTest).to have_received(:start)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'with an invalid argument' do
|
33
|
-
before do
|
34
|
-
allow(CliTest).to receive :help
|
35
|
-
CliTest.init '-foo'
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should call the help method' do
|
39
|
-
expect(CliTest).to have_received(:help)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'with the respective argument' do
|
44
|
-
options.each do |option|
|
45
|
-
before do
|
46
|
-
allow(CliTest).to receive option.to_s.downcase.to_sym
|
47
|
-
|
48
|
-
# Test both option forms
|
49
|
-
CliTest.init "-#{option.to_s.chars.first}"
|
50
|
-
CliTest.init "--#{option}"
|
51
|
-
end
|
52
|
-
|
53
|
-
the "#{option} option is valid" do
|
54
|
-
expect(CliTest).to have_received(option.to_s.downcase.to_sym).twice
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'with a menu path' do
|
60
|
-
before do
|
61
|
-
allow(CliTest).to receive :start
|
62
|
-
CliTest.init 'foo_path'
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'should set the path' do
|
66
|
-
expect(CliTest.instance_var(:path)).to eq 'foo_path'
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe '#say' do
|
72
|
-
before do
|
73
|
-
allow(CliTest).to receive(:say).and_call_original
|
74
|
-
allow(STDOUT).to receive(:puts)
|
75
|
-
end
|
76
|
-
|
77
|
-
after do
|
78
|
-
allow(STDOUT).to receive(:puts).and_call_original
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'should output the correct type' do
|
82
|
-
expect(STDOUT).to receive(:puts).with("\e[31mfoo type\e[0m")
|
83
|
-
CliTest.say 'foo type', :type => :fail
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'should output the correct color' do
|
87
|
-
expect(STDOUT).to receive(:puts).with("\e[123mfoo color\e[0m")
|
88
|
-
CliTest.say 'foo color', :color => 123
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'should output the correct justification & padding' do
|
92
|
-
expect(STDOUT).to receive(:puts).with(' foo justify padding ')
|
93
|
-
CliTest.say 'foo justify padding', :justify => :center, :padding => 22
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'should output the correct indentation' do
|
97
|
-
expect(STDOUT).to receive(:puts).with(' foo indent')
|
98
|
-
CliTest.say 'foo indent', :indent => 2
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe '#ask' do
|
103
|
-
before do
|
104
|
-
allow(CliTest).to receive(:say)
|
105
|
-
allow(STDIN).to receive(:gets).and_return 'foo'
|
106
|
-
end
|
107
|
-
|
108
|
-
after do
|
109
|
-
allow(STDIN).to receive(:gets).and_call_original
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'should pass the user input to the block' do
|
113
|
-
CliTest.ask 'why?' do |response|
|
114
|
-
expect(response).to eq 'foo'
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
describe '#command?' do
|
120
|
-
it 'should return true if command exists' do
|
121
|
-
expect(CliTest.command?('ruby -v')).to eq true
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'should return false if command does not exist' do
|
125
|
-
expect(CliTest.command?('rubyfoo')).to eq false
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe '#write_to_file' do
|
130
|
-
after do
|
131
|
-
FileUtils.rm Dir.glob('write_to_file*')
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'should create a file if it doesnt exist' do
|
135
|
-
CliTest.write_to_file 'write_to_file_create', 'foo'
|
136
|
-
|
137
|
-
expect(File.exists?('write_to_file_create')).to be true
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'should append to the file' do
|
141
|
-
CliTest.write_to_file 'write_to_file_append', 'foo'
|
142
|
-
CliTest.write_to_file 'write_to_file_append', 'bar'
|
143
|
-
|
144
|
-
expect(File.open('write_to_file_append').read).to eq "foo\nbar\n"
|
145
|
-
end
|
146
|
-
|
147
|
-
it 'should accept multiple string arguments' do
|
148
|
-
CliTest.write_to_file 'write_to_file_strings', 'line 1', 'line 2'
|
149
|
-
|
150
|
-
expect(File.open('write_to_file_strings').read).to eq "line 1\nline 2\n"
|
151
|
-
end
|
152
|
-
|
153
|
-
it 'should accept an array argument' do
|
154
|
-
CliTest.write_to_file 'write_to_file_array', ['line 1', 'line 2']
|
155
|
-
|
156
|
-
expect(File.open('write_to_file_array').read).to eq "line 1\nline 2\n"
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'should not add a line if it already exists' do
|
160
|
-
CliTest.write_to_file 'write_to_file_exists', 'foo'
|
161
|
-
CliTest.write_to_file 'write_to_file_exists', 'foo'
|
162
|
-
|
163
|
-
expect(File.open('write_to_file_exists').read).to eq "foo\n"
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
describe '#delete_from_file' do
|
168
|
-
after do
|
169
|
-
FileUtils.rm Dir.glob('delete_from_file*')
|
170
|
-
end
|
171
|
-
|
172
|
-
it 'should remove a line from the file' do
|
173
|
-
CliTest.write_to_file 'delete_from_file', 'foo', 'remove', 'bar'
|
174
|
-
CliTest.delete_from_file 'delete_from_file', 'remove'
|
175
|
-
|
176
|
-
expect(File.open('delete_from_file').read).to eq "foo\nbar\n"
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'should accept multiple string arguments' do
|
180
|
-
CliTest.write_to_file 'delete_from_file_strings', 'foo', 'remove 1', 'remove 2', 'bar'
|
181
|
-
CliTest.delete_from_file 'delete_from_file_strings', 'remove 1', 'remove 2'
|
182
|
-
|
183
|
-
expect(File.open('delete_from_file_strings').read).to eq "foo\nbar\n"
|
184
|
-
end
|
185
|
-
|
186
|
-
it 'should accept an array argument' do
|
187
|
-
CliTest.write_to_file 'delete_from_file_array', 'foo', 'remove 1', 'remove 2', 'bar'
|
188
|
-
CliTest.delete_from_file 'delete_from_file_array', ['remove 1', 'remove 2']
|
189
|
-
|
190
|
-
expect(File.open('delete_from_file_array').read).to eq "foo\nbar\n"
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
describe '#osx_version' do
|
195
|
-
it 'should return a float' do
|
196
|
-
expect(CliTest.osx_version).to be_a Float
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
describe '#get_menu' do
|
201
|
-
before do
|
202
|
-
stub_const 'Yuyi::DEFAULT_MENU', 'spec/fixtures/menu.yaml'
|
203
|
-
allow(Yuyi::Menu).to receive(:new)
|
204
|
-
allow(Yuyi::Menu).to receive(:load_from_file)
|
205
|
-
end
|
206
|
-
|
207
|
-
after do
|
208
|
-
CliTest.send :get_menu
|
209
|
-
allow(Readline).to receive(:readline).and_call_original
|
210
|
-
allow(Yuyi::Menu).to receive(:new).and_call_original
|
211
|
-
allow(Yuyi::Menu).to receive(:load_from_file).and_call_original
|
212
|
-
end
|
213
|
-
|
214
|
-
context 'when no input is given' do
|
215
|
-
before do
|
216
|
-
allow(Readline).to receive(:readline).and_return('')
|
217
|
-
allow(Yuyi::Menu).to receive(:load_from_file).and_return(true)
|
218
|
-
end
|
219
|
-
|
220
|
-
it 'should load the default menu' do
|
221
|
-
expect(Yuyi::Menu).to receive(:load_from_file).with('spec/fixtures/menu.yaml')
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
context 'when an invalid path is given' do
|
226
|
-
before do
|
227
|
-
allow(Readline).to receive(:readline).and_return('foo', 'bar', '')
|
228
|
-
allow(Yuyi::Menu).to receive(:load_from_file).and_return(false, false, true)
|
229
|
-
end
|
230
|
-
|
231
|
-
it 'should request input again' do
|
232
|
-
expect(Yuyi::Menu).to receive(:load_from_file).exactly(3).times
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
context 'when a custom path is given' do
|
237
|
-
before do
|
238
|
-
allow(Readline).to receive(:readline).and_return('spec/fixtures/menu.yaml')
|
239
|
-
allow(Yuyi::Menu).to receive(:load_from_file).and_return(true)
|
240
|
-
end
|
241
|
-
|
242
|
-
it 'should load the menu' do
|
243
|
-
expect(Yuyi::Menu).to receive(:load_from_file).with('spec/fixtures/menu.yaml')
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
describe '#present_options' do
|
249
|
-
before do
|
250
|
-
@output = ''
|
251
|
-
allow(CliTest).to receive :say do |o, p|
|
252
|
-
@output << (o || '')
|
253
|
-
end
|
254
|
-
|
255
|
-
class PresentOptionsRoll; end
|
256
|
-
allow(PresentOptionsRoll).to receive(:title).and_return 'Present Options Roll'
|
257
|
-
allow(PresentOptionsRoll).to receive(:file_name).and_return :present_options_roll
|
258
|
-
allow(PresentOptionsRoll).to receive(:options).and_return({ :option_foo => '3.0' })
|
259
|
-
allow(PresentOptionsRoll).to receive(:option_defs).and_return({
|
260
|
-
:option_foo => {
|
261
|
-
:description => 'foo description',
|
262
|
-
:example => '1.0',
|
263
|
-
:default => '2.0'
|
264
|
-
}
|
265
|
-
})
|
266
|
-
|
267
|
-
CliTest.send :present_options, PresentOptionsRoll
|
268
|
-
end
|
269
|
-
|
270
|
-
it 'should output the neccessary information' do
|
271
|
-
expect(@output).to include 'Present Options Roll'
|
272
|
-
expect(@output).to include 'present_options_roll'
|
273
|
-
expect(@output).to include 'foo description'
|
274
|
-
expect(@output).to include '1.0'
|
275
|
-
expect(@output).to include '2.0'
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
5
|
# Argument Methods
|
280
6
|
#
|
281
|
-
describe '#help' do
|
282
|
-
before do
|
283
|
-
stub_const 'Yuyi::Cli::CLI_OPTIONS', {
|
284
|
-
:FOO => 'doo',
|
285
|
-
:bar => 'boo'
|
286
|
-
}
|
287
|
-
|
288
|
-
@output = ''
|
289
|
-
allow(CliTest).to receive :say do |o, p|
|
290
|
-
@output << (o || '')
|
291
|
-
end
|
292
|
-
|
293
|
-
CliTest.send :help
|
294
|
-
end
|
295
|
-
|
296
|
-
it 'should return options' do
|
297
|
-
expect(@output).to include '-F'
|
298
|
-
expect(@output).to include '--FOO'
|
299
|
-
expect(@output).to include 'doo'
|
300
|
-
expect(@output).to include '-b'
|
301
|
-
expect(@output).to include '--bar'
|
302
|
-
expect(@output).to include 'boo'
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
7
|
describe '#list' do
|
307
8
|
before do
|
308
|
-
|
309
|
-
allow(
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
allow(Yuyi::Menu).to receive(:sources).and_return([ ListRollSource ])
|
9
|
+
allow(Yuyi::Menu).to receive :new
|
10
|
+
allow(Yuyi::Menu).to receive(:sources).and_return([
|
11
|
+
OpenStruct.new({ :rolls => { :foo => {}}}),
|
12
|
+
OpenStruct.new({ :rolls => { :bar => {}}})
|
13
|
+
])
|
314
14
|
|
315
15
|
@output = ''
|
316
|
-
allow(
|
16
|
+
allow(Yuyi).to receive :say do |o, p|
|
317
17
|
@output << (o || '')
|
318
18
|
end
|
319
19
|
|
320
|
-
|
20
|
+
Yuyi::Cli.new.send :list
|
321
21
|
end
|
322
22
|
|
323
23
|
after do
|
24
|
+
allow(Yuyi::Menu).to receive(:new).and_call_original
|
324
25
|
allow(Yuyi::Menu).to receive(:set_sources).and_call_original
|
325
26
|
end
|
326
27
|
|
327
|
-
it 'should return all rolls' do
|
328
|
-
expect(@output).to include
|
28
|
+
it 'should return all rolls alphabetically' do
|
29
|
+
expect(@output).to include "barfoo"
|
329
30
|
end
|
330
31
|
end
|
331
32
|
end
|
data/spec/lib/yuyi/core_spec.rb
CHANGED
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yuyi::Dsl do
|
4
|
+
before do
|
5
|
+
class DslTest; extend Yuyi::Dsl; end
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#say' do
|
9
|
+
before do
|
10
|
+
allow(STDOUT).to receive(:puts)
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
allow(STDOUT).to receive(:puts).and_call_original
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should output the correct type' do
|
18
|
+
expect(STDOUT).to receive(:puts).with("\e[31mfoo type\e[0m")
|
19
|
+
DslTest.say 'foo type', :type => :fail
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should output the correct color' do
|
23
|
+
expect(STDOUT).to receive(:puts).with("\e[123mfoo color\e[0m")
|
24
|
+
DslTest.say 'foo color', :color => 123
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should output the correct justification & padding' do
|
28
|
+
expect(STDOUT).to receive(:puts).with(' foo justify padding ')
|
29
|
+
DslTest.say 'foo justify padding', :justify => :center, :padding => 22
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should output the correct indentation' do
|
33
|
+
expect(STDOUT).to receive(:puts).with(' foo indent')
|
34
|
+
DslTest.say 'foo indent', :indent => 2
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#ask' do
|
39
|
+
before do
|
40
|
+
allow(DslTest).to receive(:ask)
|
41
|
+
allow(STDIN).to receive(:gets).and_return 'foo'
|
42
|
+
end
|
43
|
+
|
44
|
+
after do
|
45
|
+
allow(STDIN).to receive(:gets).and_call_original
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should pass the user input to the block' do
|
49
|
+
DslTest.ask 'why?' do |response|
|
50
|
+
expect(response).to eq 'foo'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#command?' do
|
56
|
+
it 'should return true if command exists' do
|
57
|
+
expect(DslTest.command?('ruby -v')).to eq true
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should return false if command does not exist' do
|
61
|
+
expect(DslTest.command?('rubyfoo')).to eq false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#write_to_file' do
|
66
|
+
after do
|
67
|
+
FileUtils.rm Dir.glob('write_to_file*')
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should create a file if it doesnt exist' do
|
71
|
+
DslTest.write_to_file 'write_to_file_create', 'foo'
|
72
|
+
|
73
|
+
expect(File.exists?('write_to_file_create')).to be true
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should append to the file' do
|
77
|
+
DslTest.write_to_file 'write_to_file_append', 'foo'
|
78
|
+
DslTest.write_to_file 'write_to_file_append', 'bar'
|
79
|
+
|
80
|
+
expect(File.open('write_to_file_append').read).to eq "foo\nbar\n"
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should accept multiple string arguments' do
|
84
|
+
DslTest.write_to_file 'write_to_file_strings', 'line 1', 'line 2'
|
85
|
+
|
86
|
+
expect(File.open('write_to_file_strings').read).to eq "line 1\nline 2\n"
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should accept an array argument' do
|
90
|
+
DslTest.write_to_file 'write_to_file_array', ['line 1', 'line 2']
|
91
|
+
|
92
|
+
expect(File.open('write_to_file_array').read).to eq "line 1\nline 2\n"
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should not add a line if it already exists' do
|
96
|
+
DslTest.write_to_file 'write_to_file_exists', 'foo'
|
97
|
+
DslTest.write_to_file 'write_to_file_exists', 'foo'
|
98
|
+
|
99
|
+
expect(File.open('write_to_file_exists').read).to eq "foo\n"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe '#delete_from_file' do
|
104
|
+
after do
|
105
|
+
FileUtils.rm Dir.glob('delete_from_file*')
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should remove a line from the file' do
|
109
|
+
DslTest.write_to_file 'delete_from_file', 'foo', 'remove', 'bar'
|
110
|
+
DslTest.delete_from_file 'delete_from_file', 'remove'
|
111
|
+
|
112
|
+
expect(File.open('delete_from_file').read).to eq "foo\nbar\n"
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should accept multiple string arguments' do
|
116
|
+
DslTest.write_to_file 'delete_from_file_strings', 'foo', 'remove 1', 'remove 2', 'bar'
|
117
|
+
DslTest.delete_from_file 'delete_from_file_strings', 'remove 1', 'remove 2'
|
118
|
+
|
119
|
+
expect(File.open('delete_from_file_strings').read).to eq "foo\nbar\n"
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should accept an array argument' do
|
123
|
+
DslTest.write_to_file 'delete_from_file_array', 'foo', 'remove 1', 'remove 2', 'bar'
|
124
|
+
DslTest.delete_from_file 'delete_from_file_array', ['remove 1', 'remove 2']
|
125
|
+
|
126
|
+
expect(File.open('delete_from_file_array').read).to eq "foo\nbar\n"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe '#osx_version' do
|
131
|
+
it 'should return a float' do
|
132
|
+
expect(DslTest.osx_version).to be_a Float
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|