/
dsl_spec.rb
259 lines (191 loc) · 7.78 KB
/
dsl_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
require 'spec_helper'
describe Gitara do
describe Dsl do
describe "bar(name, &block)" do
it "should add a bar with the name" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
dsl.node.own_children.should be_empty
dsl.bar 'Intro'
dsl.node.own_children.should have(1).bar
bar = dsl.node.own_children[0]
bar.name.should == 'Intro'
bar.own_children.should be_empty
end
it "should add the children declared in the block to the bar" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
dsl.node.own_children.should be_empty
note_set = FactoryGirl.build(:note_set)
dsl.bar 'Intro' do
add note_set
end
dsl.node.own_children.should have(1).bar
dsl.node.own_children[0].name.should == 'Intro'
bar = dsl.node.own_children[0]
bar.own_children.should have(1).note_set
bar.own_children[0].should == note_set
end
end
describe "add(child, &block)" do
it "should add the child to the dsl's node" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
dsl.node.own_children.should be_empty
bar = FactoryGirl.build(:bar, :name => 'Intro')
dsl.add bar
dsl.node.own_children.should have(1).bar
dsl.node.own_children[0].should == bar
end
it "should add the children in the block to the child" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
dsl.node.own_children.should be_empty
bar = FactoryGirl.build(:bar, :children => [])
note_set = FactoryGirl.build(:note_set)
dsl.add bar do
add note_set
end
dsl.node.own_children.should have(1).bar
dsl.node.own_children[0].should == bar
bar.own_children.should have(1).note_set
bar.own_children[0].should == note_set
end
end
describe "notes(value)" do
it "should add a note set with the value" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:bar, :children => []))
dsl.node.own_children.should be_empty
dsl.notes 'test'
dsl.node.own_children.should have(1).note_set
dsl.node.own_children[0].value.should == 'test'
end
end
describe "line(name, &block)" do
it "should add a line with the name" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
dsl.node.own_children.should be_empty
dsl.line 'Intro'
dsl.node.own_children.should have(1).line
line = dsl.node.own_children[0]
line.name.should == 'Intro'
line.own_children.should be_empty
end
it "should add the children declared in the block to the line" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
dsl.node.own_children.should be_empty
bar = FactoryGirl.build(:bar)
dsl.line 'Intro' do
add bar
end
dsl.node.own_children.should have(1).line
dsl.node.own_children[0].name.should == 'Intro'
line = dsl.node.own_children[0]
line.own_children.should have(1).bar
line.own_children[0].should == bar
end
end
describe "add_names(o)" do
it "should add a node with o[:name] of o[:node_class] to the node" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
dsl.node.own_children.should be_empty
dsl.add_names :names => [:Intro, :Intro], :node_class => Node::Bar
dsl.node.own_children.should have(2).bars
dsl.node.own_children.each do |child|
child.should be_a(Node::Bar)
child.name.should == :Intro
end
end
it "should add a node with nil name if the o[:names] is blank" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
dsl.node.own_children.should be_empty
dsl.add_names :names => [], :node_class => Node::Bar
dsl.node.own_children.should have(1).bar
dsl.node.own_children[0].attributes[:name].should be_nil
dsl.node.own_children[0].should be_a(Node::Bar)
end
end
describe "score(name, &block)" do
it "should add a score with the name" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
dsl.node.own_children.should be_empty
dsl.score
dsl.node.own_children.should have(1).score
score = dsl.node.own_children[0]
score.should be_a(Node::Score)
score.own_children.should be_empty
end
it "should add the children declared in the block to the score" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
dsl.node.own_children.should be_empty
note_set = FactoryGirl.build(:note_set)
dsl.score do
add note_set
end
dsl.node.own_children.should have(1).score
score = dsl.node.own_children[0]
score.own_children.should have(1).note_set
score.own_children[0].should == note_set
end
end
describe "stanza(name, &block)" do
it "should add a stanza with the name" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
dsl.node.own_children.should be_empty
dsl.stanza 'Intro'
dsl.node.own_children.should have(1).stanza
stanza = dsl.node.own_children[0]
stanza.name.should == 'Intro'
stanza.own_children.should be_empty
end
it "should add the children declared in the block to the stanza" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
dsl.node.own_children.should be_empty
line = FactoryGirl.build(:line)
dsl.stanza 'Intro' do
add line
end
dsl.node.own_children.should have(1).stanza
dsl.node.own_children[0].name.should == 'Intro'
stanza = dsl.node.own_children[0]
stanza.own_children.should have(1).line
stanza.own_children[0].should == line
end
end
[:title, :composer, :arranger, :instrument, :midi_instrument, :tempo, :transposition].each do |property|
describe "#{property}(value)" do
it "should set the #{property} of the tab to value" do
tab = FactoryGirl.build(:tab)
dsl = FactoryGirl.build(:dsl, :node => tab)
dsl.send property, "test"
tab.send(property).should == "test"
end
end
end
describe "chords(name, value)" do
it "should add a chord set with the name" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
dsl.node.own_children.should be_empty
dsl.chords :Am, 'r4-"Am" r r r'
dsl.node.own_children.should have(1).chord_set
chord_set = dsl.node.own_children[0]
chord_set.name.should == :Am
chord_set.value.should == 'r4-"Am" r r r'
end
end
describe "chords(name)" do
it "should add a bar with the name" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:tab, :children => []))
dsl.node.own_children.should be_empty
dsl.chords :Am
dsl.node.own_children.should have(1).chord_set
chord_set = dsl.node.own_children[0]
chord_set.name.should == :Am
end
end
describe "partial(duration)" do
it "should set the specified duration of the bar node to duration" do
dsl = FactoryGirl.build(:dsl, :node => FactoryGirl.build(:bar))
dsl.node.specified_duration.should be_nil
dsl.partial 8
dsl.node.specified_duration.should == 8
end
end
end
end