yuyi 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.new +1 -1
- data/lib/yuyi/menu.rb +2 -2
- data/spec/lib/yuyi/menu_spec.rb +141 -128
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d42b24d7281505899a99092cf0deffad8806cfe
|
4
|
+
data.tar.gz: e7f8ae082e4a25f178d530613624def9f28eedb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1a8ca7384b13712ec2b6f7929e3e6351ccf1f8e628c40729ee30e9a4746a489bc56bfad9bd396575b84290f2f8ee04751e404df7455b1a14c49c29d80767a34
|
7
|
+
data.tar.gz: 3ef10a04e372744cc27f2b950b636b666674a2be54d61e7acfe9e8d7ca84945f1159658a784ab7feee48f462aa26d8316606031a9f6868da4f525c3d8de3af42
|
data/.new
CHANGED
data/lib/yuyi/menu.rb
CHANGED
@@ -40,13 +40,13 @@ class Yuyi::Menu
|
|
40
40
|
end
|
41
41
|
|
42
42
|
# Attempt to load a menu from a file path
|
43
|
-
# defaults to previously stored @path value
|
44
43
|
#
|
45
44
|
def self.load_from_file path = path
|
46
45
|
menu = begin
|
47
46
|
File.open(File.expand_path(path))
|
48
47
|
rescue
|
49
|
-
Yuyi.run "curl -sS #{path}"
|
48
|
+
response = Yuyi.run "curl -sS #{path}"
|
49
|
+
$?.success? ? response : nil
|
50
50
|
end
|
51
51
|
|
52
52
|
@object = begin
|
data/spec/lib/yuyi/menu_spec.rb
CHANGED
@@ -2,194 +2,207 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Yuyi::Menu do
|
4
4
|
before do
|
5
|
-
|
5
|
+
Yuyi::Menu.send :class_variable_set, :'@@instance', nil
|
6
|
+
Yuyi::Menu.send :instance_variable_set, :'@object', nil
|
6
7
|
end
|
7
8
|
|
8
|
-
describe '
|
9
|
-
context 'with a
|
9
|
+
describe '#initialize' do
|
10
|
+
context 'with a valid path' do
|
10
11
|
before do
|
11
|
-
Yuyi::Menu.
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should update the menu object' do
|
15
|
-
expect(@menu.object[:rolls][:foo_roll]).to eq({ :bar => 'foo' })
|
12
|
+
Yuyi::Menu.new 'spec/fixtures/menu.yaml'
|
16
13
|
end
|
17
|
-
end
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
allow(Yuyi).to receive(:run).and_return({ :foo => 'bar' }.to_yaml)
|
22
|
-
Yuyi::Menu.load_from_file 'file://menu.yaml'
|
15
|
+
it 'should set the path var' do
|
16
|
+
expect(Yuyi::Menu.path).to eq 'spec/fixtures/menu.yaml'
|
23
17
|
end
|
24
18
|
|
25
|
-
|
26
|
-
|
19
|
+
it 'should set the instance on the menu class' do
|
20
|
+
expect(Yuyi::Menu.instance).to eq Yuyi::Menu.instance
|
27
21
|
end
|
28
22
|
|
29
|
-
it 'should
|
30
|
-
expect(
|
23
|
+
it 'should set the object var' do
|
24
|
+
expect(Yuyi::Menu.object[:sources][0]).to eq({ :local => 'spec/fixtures/roll_dir' })
|
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' })
|
31
27
|
end
|
32
28
|
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '.add_roll' do
|
36
|
-
before do
|
37
|
-
class MenuAddRollRoll; end
|
38
|
-
Yuyi::Menu.add_roll :menu_add_roll_roll, MenuAddRollRoll
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should add a roll instance' do
|
42
|
-
expect(Yuyi::Menu.instance_var(:rolls)[:menu_add_roll_roll]).to be_a MenuAddRollRoll
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#initialize' do
|
47
|
-
it 'should set the path var' do
|
48
|
-
expect(@menu.var(:path)).to eq 'spec/fixtures/menu.yaml'
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should set the instance on the menu class' do
|
52
|
-
expect(Yuyi::Menu.instance).to eq @menu
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should set the object var' do
|
56
|
-
expect(Yuyi::Menu.instance_var(:object)[:sources][0]).to eq({ :local => 'spec/fixtures/roll_dir' })
|
57
|
-
expect(Yuyi::Menu.instance_var(:object)[:sources][1]).to eq({ :yuyi => 'spec/fixtures/roll_zip.zip' })
|
58
|
-
expect(Yuyi::Menu.instance_var(:object)[:rolls][:foo_roll]).to eq({ :foo => 'bar' })
|
59
|
-
end
|
60
29
|
|
61
30
|
context 'with an invalid path' do
|
62
31
|
before do
|
63
|
-
|
32
|
+
Yuyi::Menu.new 'foo'
|
64
33
|
end
|
65
34
|
|
66
|
-
it 'should
|
67
|
-
expect(Yuyi::Menu).
|
35
|
+
it 'should have a nil instance' do
|
36
|
+
expect(Yuyi::Menu.instance).to be_nil
|
68
37
|
end
|
69
38
|
|
70
39
|
it 'should have a nil object' do
|
71
|
-
expect(Yuyi::Menu.
|
40
|
+
expect(Yuyi::Menu.object).to be_nil
|
72
41
|
end
|
73
42
|
end
|
74
43
|
end
|
75
44
|
|
76
|
-
|
45
|
+
context 'when valid menu already initialized' do
|
77
46
|
before do
|
78
|
-
Yuyi::Menu.
|
47
|
+
Yuyi::Menu.new 'spec/fixtures/menu.yaml'
|
48
|
+
end
|
79
49
|
|
80
|
-
|
81
|
-
|
50
|
+
describe '.load_from_file' do
|
51
|
+
context 'with a local file' do
|
52
|
+
before do
|
53
|
+
Yuyi::Menu.load_from_file 'spec/fixtures/menu2.yaml'
|
54
|
+
end
|
82
55
|
|
83
|
-
|
84
|
-
|
56
|
+
it 'should update the menu object' do
|
57
|
+
expect(Yuyi::Menu.instance.object[:rolls][:foo_roll]).to eq({ :bar => 'foo' })
|
58
|
+
end
|
59
|
+
end
|
85
60
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
61
|
+
context 'with a remote file' do
|
62
|
+
before do
|
63
|
+
allow(Yuyi).to receive(:run).and_return({ :foo => 'bar' }.to_yaml)
|
64
|
+
Yuyi::Menu.load_from_file 'file://menu.yaml'
|
65
|
+
end
|
91
66
|
|
92
|
-
|
93
|
-
|
94
|
-
|
67
|
+
after do
|
68
|
+
allow(Yuyi).to receive(:run).and_call_original
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should update the menu object' do
|
72
|
+
expect(Yuyi::Menu.instance.object[:foo]).to eq 'bar'
|
73
|
+
end
|
74
|
+
end
|
95
75
|
end
|
96
76
|
|
97
|
-
|
77
|
+
describe '.add_roll' do
|
98
78
|
before do
|
99
|
-
|
79
|
+
class MenuAddRollRoll; end
|
80
|
+
Yuyi::Menu.add_roll :menu_add_roll_roll, MenuAddRollRoll
|
100
81
|
end
|
101
82
|
|
102
|
-
it 'should
|
103
|
-
expect(
|
83
|
+
it 'should add a roll instance' do
|
84
|
+
expect(Yuyi::Menu.instance_var(:rolls)[:menu_add_roll_roll]).to be_a MenuAddRollRoll
|
104
85
|
end
|
105
86
|
end
|
106
87
|
|
107
|
-
|
88
|
+
describe '#set_sources' do
|
108
89
|
before do
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
allow(
|
90
|
+
Yuyi::Menu.instance_var :object, { :sources => [{ :foo_source => 'foo/path' }]}
|
91
|
+
|
92
|
+
class FooSource; end
|
93
|
+
allow(Yuyi::Source).to receive(:new).and_return FooSource
|
113
94
|
|
114
|
-
|
95
|
+
Yuyi::Menu.instance.send :set_sources
|
115
96
|
end
|
116
97
|
|
117
|
-
it 'should
|
118
|
-
expect(
|
119
|
-
|
98
|
+
it 'should set the sources var' do
|
99
|
+
expect(Yuyi::Menu.instance.var(:sources).size).to eq(1)
|
100
|
+
expect(Yuyi::Menu.instance.var(:sources)[0]).to eq FooSource
|
120
101
|
end
|
121
102
|
end
|
122
103
|
|
123
|
-
|
104
|
+
describe '#find_roll' do
|
124
105
|
before do
|
125
|
-
|
126
|
-
|
106
|
+
allow(Yuyi::Menu.instance).to receive :require_roll
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'when a source is specified' do
|
110
|
+
before do
|
111
|
+
Yuyi::Menu.instance.send :find_roll, :foo_roll, { :source => 'foo_source' }
|
112
|
+
end
|
127
113
|
|
128
|
-
|
114
|
+
it 'should require the specific roll' do
|
115
|
+
expect(Yuyi::Menu.instance).to have_received(:require_roll).once.with(:foo_roll, 'foo_source/foo_roll')
|
116
|
+
end
|
129
117
|
end
|
130
118
|
|
131
|
-
|
132
|
-
|
133
|
-
|
119
|
+
context 'when no source is specified' do
|
120
|
+
before do
|
121
|
+
class TestSourceA; end
|
122
|
+
class TestSourceB; end
|
123
|
+
allow(TestSourceA).to receive(:available_rolls).and_return({ :foo_roll => 'foo_roll' })
|
124
|
+
allow(TestSourceB).to receive(:available_rolls).and_return({ :bar_roll => 'bar_roll' })
|
125
|
+
|
126
|
+
Yuyi::Menu.instance.var :sources, [TestSourceA, TestSourceB]
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should require the first roll found' do
|
130
|
+
expect(Yuyi::Menu.instance).to receive(:require_roll).once.with(:bar_roll, 'bar_roll')
|
131
|
+
Yuyi::Menu.instance.send :find_roll, :bar_roll
|
132
|
+
end
|
134
133
|
end
|
135
|
-
end
|
136
|
-
end
|
137
134
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
135
|
+
context 'when no roll is found' do
|
136
|
+
before do
|
137
|
+
class TestSource; end
|
138
|
+
allow(TestSource).to receive(:available_rolls).and_return({})
|
142
139
|
|
143
|
-
|
144
|
-
|
140
|
+
Yuyi::Menu.instance.var :sources, [TestSource]
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should not attempt to require a roll' do
|
144
|
+
expect(Yuyi::Menu.instance).to_not receive(:require_roll)
|
145
|
+
Yuyi::Menu.instance.send :find_roll, :no_roll
|
146
|
+
end
|
147
|
+
end
|
145
148
|
end
|
146
|
-
end
|
147
149
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
def dependencies; ['foo', 'bar']; end
|
150
|
+
describe '#on_the_menu?' do
|
151
|
+
before do
|
152
|
+
allow(Yuyi::Menu.instance).to receive(:object).and_return({ :rolls => { :foo => nil }})
|
152
153
|
end
|
153
|
-
|
154
|
-
|
154
|
+
|
155
|
+
it 'should return true if on the menu' do
|
156
|
+
expect(Yuyi::Menu.instance.on_the_menu?(:foo)).to be true
|
155
157
|
end
|
156
|
-
allow(@menu).to receive(:rolls).and_return({ :dependency_roll => DependencyRoll.new, :foo => EmptyDependencyRoll.new, :bar => EmptyDependencyRoll.new })
|
157
158
|
end
|
158
159
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
163
170
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
class MenuOrderRollsTwo; end
|
168
|
-
allow(MenuOrderRollsOne).to receive :appetizers
|
169
|
-
allow(MenuOrderRollsTwo).to receive :appetizers
|
170
|
-
allow(MenuOrderRollsOne).to receive :entree
|
171
|
-
allow(MenuOrderRollsTwo).to receive :entree
|
172
|
-
allow(MenuOrderRollsOne).to receive :dessert
|
173
|
-
allow(MenuOrderRollsTwo).to receive :dessert
|
174
|
-
|
175
|
-
allow(@menu).to receive(:sorted_rolls).and_return([:menu_order_rolls_one, :menu_order_rolls_two])
|
176
|
-
allow(@menu).to receive(:rolls).and_return({ :menu_order_rolls_one => MenuOrderRollsOne, :menu_order_rolls_two => MenuOrderRollsTwo })
|
177
|
-
|
178
|
-
@menu.send :order_rolls
|
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
|
179
174
|
end
|
180
175
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
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
|
185
186
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
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
|
205
|
+
end
|
193
206
|
end
|
194
207
|
end
|
195
208
|
end
|