gitara 0.4.0 → 0.4.1

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.
Files changed (47) hide show
  1. data/CHANGELOG.markdown +5 -0
  2. data/examples/eraserheads-huling-el-bimbo/tab.ly +333 -0
  3. data/examples/eraserheads-huling-el-bimbo/tab.midi +0 -0
  4. data/examples/eraserheads-huling-el-bimbo/tab.pdf +0 -0
  5. data/examples/eraserheads-huling-el-bimbo/tab.rb +249 -0
  6. data/examples/tab.ly +11 -3
  7. data/gitara.gemspec +1 -0
  8. data/lib/gitara.rb +8 -5
  9. data/lib/gitara/is_node_version.rb +23 -0
  10. data/lib/gitara/node/bar.rb +12 -0
  11. data/lib/gitara/node/bar/{chorded_node.rb → chorded_version.rb} +1 -1
  12. data/lib/gitara/node/bar/stanza_version.rb +11 -0
  13. data/lib/gitara/node/bar/{voiced_node.rb → voiced_version.rb} +1 -1
  14. data/lib/gitara/node/base.rb +11 -2
  15. data/lib/gitara/node/base/chorded_version.rb +11 -0
  16. data/lib/gitara/node/base/stanza_version.rb +11 -0
  17. data/lib/gitara/node/base/{voiced_node.rb → voiced_version.rb} +5 -7
  18. data/lib/gitara/node/chord_set/{chorded_node.rb → chorded_version.rb} +1 -1
  19. data/lib/gitara/template/bar.erb +1 -0
  20. data/lib/gitara/template/line.erb +2 -1
  21. data/lib/gitara/template/score.erb +2 -1
  22. data/lib/gitara/template/stanza.erb +2 -1
  23. data/lib/gitara/template/tab.erb +1 -5
  24. data/lib/gitara/version.rb +1 -1
  25. data/spec/factories.rb +54 -0
  26. data/spec/lib/gitara/app_spec.rb +1 -1
  27. data/spec/lib/gitara/dsl_spec.rb +24 -24
  28. data/spec/lib/gitara/is_node_version_spec.rb +58 -0
  29. data/spec/lib/gitara/node/bar/chorded_version_spec.rb +20 -0
  30. data/spec/lib/gitara/node/bar/stanza_version_spec.rb +14 -0
  31. data/spec/lib/gitara/node/bar/voiced_version_spec.rb +16 -0
  32. data/spec/lib/gitara/node/bar_spec.rb +39 -7
  33. data/spec/lib/gitara/node/base/chorded_version_spec.rb +5 -0
  34. data/spec/lib/gitara/node/base/voiced_version_spec.rb +28 -0
  35. data/spec/lib/gitara/node/base_spec.rb +87 -79
  36. data/spec/lib/gitara/node/chord_set/chorded_version_spec.rb +11 -0
  37. data/spec/lib/gitara/node/stanza_spec.rb +4 -4
  38. data/spec/lib/gitara/node/tab_spec.rb +21 -32
  39. data/spec/lib/gitara/voice_spec.rb +21 -21
  40. data/spec/spec_helper.rb +2 -0
  41. metadata +141 -171
  42. data/lib/gitara/node/base/chorded_node.rb +0 -21
  43. data/spec/lib/gitara/node/bar/chorded_node_spec.rb +0 -20
  44. data/spec/lib/gitara/node/bar/voiced_node_spec.rb +0 -17
  45. data/spec/lib/gitara/node/base/chorded_node_spec.rb +0 -29
  46. data/spec/lib/gitara/node/base/voiced_node_spec.rb +0 -35
  47. data/spec/lib/gitara/node/chord_set/chorded_node_spec.rb +0 -11
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe IsNodeVersion do
4
+ class DummyVersion < Valuable
5
+ include IsNodeVersion
6
+
7
+ has_value :node
8
+ end
9
+
10
+ describe "prefix" do
11
+ it "should be by default the first letter of the class" do
12
+ dummy_version = DummyVersion.new
13
+ dummy_version.extend(IsNodeVersion)
14
+ dummy_version.prefix.should == 'd'
15
+ end
16
+ end
17
+
18
+ describe "definition_name" do
19
+ it "should include the node's class and the node's name" do
20
+ dummy_version = DummyVersion.new(:node => FactoryGirl.build(:base, :name => 'some node'))
21
+ dummy_version.definition_name.should == 'dBaseSomeNode'
22
+ end
23
+ end
24
+
25
+ describe "call_name" do
26
+ it "should be the call version of the definition name" do
27
+ dummy_version = DummyVersion.new(:node => FactoryGirl.build(:base, :name => 'some node'))
28
+ dummy_version.call_name.should == '\dBaseSomeNode'
29
+ end
30
+ end
31
+
32
+ describe "value" do
33
+ it "should be the call names of its children" do
34
+ node = FactoryGirl.build(:base, :children => [
35
+ FactoryGirl.build(:base, :name => :First),
36
+ FactoryGirl.build(:base, :name => :Second)
37
+ ])
38
+ node_version = DummyVersion.new(:node => node)
39
+ node_version.value.should == '\dBaseFirst \dBaseSecond'
40
+ end
41
+ end
42
+
43
+ describe "children" do
44
+ it "should be versionized versions of the node's children" do
45
+ parent = FactoryGirl.build(:base, :name => 'parent')
46
+ child = FactoryGirl.build(:base, :name => 'child')
47
+ parent.add child
48
+
49
+ node_version = DummyVersion.new(:node => parent)
50
+
51
+ children = node_version.children
52
+ children.should have(1).child
53
+ children[0].node.should == child
54
+ children[0].should be_a(DummyVersion)
55
+ end
56
+ end
57
+ end
58
+
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ChordedVersion' do
4
+ describe "value" do
5
+ it "should be the call names of the chord sets in the bar, if available" do
6
+ bar = FactoryGirl.build(:bar, :children => [FactoryGirl.build(:chord_set, :name => :Am, :value => 'r-"Am"')])
7
+
8
+ chorded_bar = FactoryGirl.build(:chorded_bar, :node => bar)
9
+ chorded_bar.value.should == '\cChordSetAm'
10
+ end
11
+
12
+ it "should be blank, if the bar does not have any chord sets" do
13
+ bar = FactoryGirl.build(:bar, :children => [FactoryGirl.build(:note_set, :value => 'c')])
14
+
15
+ chorded_bar = FactoryGirl.build(:chorded_bar, :node => bar)
16
+ chorded_bar.value.should == ""
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'StanzaVersion' do
4
+ describe "value" do
5
+ it "should be the stanza heading of the bar" do
6
+ bar = FactoryGirl.build(:bar)
7
+ stanza = FactoryGirl.build(:stanza, :name => 'Intro', :children => [bar])
8
+
9
+ stanza_version_of_bar = FactoryGirl.build(:stanza_version_bar, :node => bar)
10
+ stanza_version_of_bar.value.should == 'r1^"Intro"'
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Bar::VoicedVersion' do
4
+ describe "matching_note_set" do
5
+ it "should be the note_set matching this voiced bar" do
6
+ note_set = FactoryGirl.build(:note_set)
7
+
8
+ bar = FactoryGirl.build(:bar, :children => [note_set])
9
+
10
+ voice = FactoryGirl.build(:voice, :id => 1)
11
+
12
+ voiced_bar = FactoryGirl.build(:voiced_bar, :node => bar, :voice => voice)
13
+ voiced_bar.matching_note_set.should == note_set
14
+ end
15
+ end
16
+ end
@@ -3,20 +3,52 @@ require 'spec_helper'
3
3
  describe 'Bar' do
4
4
  describe "note_sets" do
5
5
  it "should be the note sets of its definition" do
6
- definition_bar = Node::Bar.new(:name => 'Intro').tap {|bar|
6
+ definition_bar = FactoryGirl.build(:bar, :name => 'Intro').tap {|bar|
7
7
  bar.children = [
8
- Node::NoteSet.new,
9
- Node::NoteSet.new
8
+ FactoryGirl.build(:note_set),
9
+ FactoryGirl.build(:note_set)
10
10
  ]
11
11
  }
12
12
 
13
- call_bar = Node::Bar.new(:name => 'Intro')
13
+ call_bar = FactoryGirl.build(:bar, :name => 'Intro', :children => [])
14
14
 
15
- tab = Node::Tab.new.tap {|tab|
16
- tab.children = [definition_bar, call_bar]
17
- }
15
+ tab = FactoryGirl.build(:tab, :children => [definition_bar, call_bar])
18
16
 
19
17
  call_bar.note_sets.should have(2).note_sets
20
18
  end
21
19
  end
20
+
21
+ describe "stanza_heading" do
22
+ it "should be a whole rest with the stanza name if the bar is the first node of a stanza" do
23
+ bar = FactoryGirl.build(:bar)
24
+ stanza = FactoryGirl.build(:stanza, :name => 'Intro', :children => [bar])
25
+
26
+ bar.stanza_heading.should == 'r1^"Intro"'
27
+ end
28
+
29
+ it "should be a whole rest with no stanza name if the bar is not the first node of a stanza" do
30
+ bar = FactoryGirl.build(:bar)
31
+ bar.stanza_heading.should == 'r1'
32
+ end
33
+ end
34
+
35
+ describe "first_bar_of_stanza?" do
36
+ it "should be true if the bar is the first bar of a stanza" do
37
+ bar = FactoryGirl.build(:bar)
38
+ stanza = FactoryGirl.build(:stanza, :name => 'Intro', :children => [bar])
39
+ bar.should be_first_bar_of_stanza
40
+ end
41
+
42
+ it "should be false if the bar is not the first bar of a stanza" do
43
+ bars = [FactoryGirl.build(:bar), FactoryGirl.build(:bar)]
44
+ stanza = FactoryGirl.build(:stanza, :name => 'Intro', :children => bars)
45
+
46
+ bars[1].should_not be_first_bar_of_stanza
47
+ end
48
+
49
+ it "should be false if the bar does not belong to a stanza" do
50
+ bar = FactoryGirl.build(:bar)
51
+ bar.should_not be_first_bar_of_stanza
52
+ end
53
+ end
22
54
  end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ChordedVersion' do
4
+ end
5
+
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'VoicedVersion' do
4
+ describe "prefix" do
5
+ it "should be based on the voice's id" do
6
+ voiced_version = FactoryGirl.build(:voiced_version, :node => FactoryGirl.build(:base, :name => 'Intro'), :voice => FactoryGirl.build(:voice, :id => 1))
7
+ voiced_version.prefix.should == 'vOne'
8
+ end
9
+ end
10
+
11
+ describe "children" do
12
+ it "should be voiced versions of the node's children" do
13
+ parent = FactoryGirl.build(:base, :name => 'parent')
14
+ child = FactoryGirl.build(:base, :name => 'child')
15
+ parent.add child
16
+
17
+ voice = FactoryGirl.build(:voice, :id => 1)
18
+
19
+ voiced_version = FactoryGirl.build(:voiced_version, :node => parent, :voice => voice)
20
+
21
+ children = voiced_version.children
22
+ children.should have(1).voiced_version
23
+ children[0].node.should == child
24
+ children[0].voice.should == voice
25
+ end
26
+ end
27
+ end
28
+
@@ -3,24 +3,22 @@ require 'spec_helper'
3
3
  describe Node::Base do
4
4
  describe "children" do
5
5
  it "should be its own children if they exist" do
6
- child = Node::Base.new(:id => nil)
6
+ child = FactoryGirl.build(:base, :id => nil)
7
7
 
8
- parent = Node::Base.new
8
+ parent = FactoryGirl.build(:base)
9
9
  parent.children = [child]
10
10
  parent.children.should == [child]
11
11
  end
12
12
 
13
13
  it "should be the children of its definition if the node is not a definition" do
14
- child = Node::NoteSet.new
15
- definition_bar = Node::Bar.new(:name => 'Intro').tap {|bar|
14
+ child = FactoryGirl.build(:note_set)
15
+ definition_bar = FactoryGirl.build(:bar, :name => 'Intro').tap {|bar|
16
16
  bar.children = [child]
17
17
  }
18
18
 
19
- call_bar = Node::Bar.new(:name => 'Intro')
19
+ call_bar = FactoryGirl.build(:bar, :name => 'Intro', :children => [])
20
20
 
21
- tab = Node::Tab.new.tap {|tab|
22
- tab.children = [definition_bar, call_bar]
23
- }
21
+ tab = FactoryGirl.build(:tab, :children => [definition_bar, call_bar])
24
22
 
25
23
  call_bar.children.should == [child]
26
24
  end
@@ -28,8 +26,8 @@ describe Node::Base do
28
26
 
29
27
  describe "children=(other)" do
30
28
  it "should set the ids and parents of the children" do
31
- parent = Node::Base.new
32
- parent.children = [Node::Base.new(:id => nil)]
29
+ parent = FactoryGirl.build(:base)
30
+ parent.children = [FactoryGirl.build(:base, :id => nil)]
33
31
  parent.children[0].id.should == 1
34
32
  parent.children[0].parent.should == parent
35
33
  end
@@ -37,29 +35,29 @@ describe Node::Base do
37
35
 
38
36
  describe "add(child)" do
39
37
  it "should set the id and parent of the child" do
40
- parent = Node::Base.new
38
+ parent = FactoryGirl.build(:base)
41
39
 
42
- parent.add Node::Base.new(:id => nil)
40
+ parent.add FactoryGirl.build(:base, :id => nil)
43
41
  parent.children[0].id.should == 1
44
42
  parent.children[0].parent.should == parent
45
43
 
46
- parent.add Node::Base.new(:id => nil)
44
+ parent.add FactoryGirl.build(:base, :id => nil)
47
45
  parent.children[1].id.should == 2
48
46
  parent.children[1].parent.should == parent
49
47
  end
50
48
 
51
49
  it "should set the id based on existing siblings having the same class as the child" do
52
- parent = Node::Base.new
50
+ parent = FactoryGirl.build(:base)
53
51
 
54
- bar_1 = Node::Bar.new
52
+ bar_1 = FactoryGirl.build(:bar)
55
53
  parent.add bar_1
56
54
  bar_1.id.should == 1
57
55
 
58
- line_1 = Node::Line.new
56
+ line_1 = FactoryGirl.build(:line)
59
57
  parent.add line_1
60
58
  line_1.id.should == 1
61
59
 
62
- bar_2 = Node::Bar.new
60
+ bar_2 = FactoryGirl.build(:bar)
63
61
  parent.add bar_2
64
62
  bar_2.id.should == 2
65
63
  end
@@ -67,18 +65,16 @@ describe Node::Base do
67
65
 
68
66
  describe "definition" do
69
67
  it "should be the definition node which matches this node's name" do
70
- definition_bar = Node::Bar.new(:name => 'Intro').tap {|bar|
68
+ definition_bar = FactoryGirl.build(:bar, :name => 'Intro').tap {|bar|
71
69
  bar.children = [
72
- Node::NoteSet.new,
73
- Node::NoteSet.new
70
+ FactoryGirl.build(:note_set),
71
+ FactoryGirl.build(:note_set)
74
72
  ]
75
73
  }
76
74
 
77
- call_bar = Node::Bar.new(:name => 'Intro')
75
+ call_bar = FactoryGirl.build(:bar, :name => 'Intro', :children => [])
78
76
 
79
- tab = Node::Tab.new.tap {|tab|
80
- tab.children = [definition_bar, call_bar]
81
- }
77
+ tab = FactoryGirl.build(:tab, :children => [definition_bar, call_bar])
82
78
 
83
79
  call_bar.send(:definition).should == definition_bar
84
80
  end
@@ -86,21 +82,21 @@ describe Node::Base do
86
82
 
87
83
  describe "definition?" do
88
84
  it "should be true if this node has children" do
89
- definition_bar = Node::Bar.new(:name => 'Intro').tap {|bar|
90
- bar.add Node::NoteSet.new
91
- bar.add Node::NoteSet.new
85
+ definition_bar = FactoryGirl.build(:bar, :name => 'Intro').tap {|bar|
86
+ bar.add FactoryGirl.build(:note_set)
87
+ bar.add FactoryGirl.build(:note_set)
92
88
  }
93
89
  definition_bar.should be_definition
94
90
  end
95
91
 
96
92
  it "should be true if the node has a value" do
97
- chord_set = Node::ChordSet.new(:name => :Am, :value =>'r4-"Am" r r r')
93
+ chord_set = FactoryGirl.build(:chord_set, :name => :Am, :value =>'r4-"Am" r r r')
98
94
  chord_set.own_children.should be_empty
99
95
  chord_set.should be_definition
100
96
  end
101
97
 
102
98
  it "should be false if this node does not have children and it does not have a value" do
103
- call_bar = Node::Bar.new(:name => 'Intro')
99
+ call_bar = FactoryGirl.build(:bar, :name => 'Intro', :children => [])
104
100
  call_bar.own_children.should be_empty
105
101
  call_bar.value.should be_nil
106
102
  call_bar.should_not be_definition
@@ -109,31 +105,31 @@ describe Node::Base do
109
105
 
110
106
  describe "value" do
111
107
  it "should convert slashes to backslashes" do
112
- node = Node::Base.new(:value => %q|notes "<g'/1>8 <a/3>8 <g'/1>8 <a/3>16 <g'/1>8 <g/3>16 <e'/1>4 <g/3>8"|)
108
+ node = FactoryGirl.build(:base, :value => %q|notes "<g'/1>8 <a/3>8 <g'/1>8 <a/3>16 <g'/1>8 <g/3>16 <e'/1>4 <g/3>8"|)
113
109
  node.value.should == %q|notes "<g'\1>8 <a\3>8 <g'\1>8 <a\3>16 <g'\1>8 <g\3>16 <e'\1>4 <g\3>8"|
114
110
  end
115
111
  end
116
112
 
117
113
  describe "voiced_as(arg)" do
118
114
  it "should return the voiced version of the node, if arg is a voice" do
119
- node = Node::Base.new
120
- voice = Voice.new
115
+ node = FactoryGirl.build(:base)
116
+ voice = FactoryGirl.build(:voice)
121
117
 
122
118
  node_voice_pair = node.voiced_as(voice)
123
- node_voice_pair.should be_a(Node::Base::VoicedNode)
119
+ node_voice_pair.should be_a(Node::Base::VoicedVersion)
124
120
  node_voice_pair.node.should == node
125
121
  node_voice_pair.voice.should == voice
126
122
  end
127
123
 
128
124
  it "should return the voiced versions of the node, if arg are voices" do
129
- node = Node::Base.new
130
- voices = [Voice.new, Voice.new]
125
+ node = FactoryGirl.build(:base)
126
+ voices = [FactoryGirl.build(:voice), FactoryGirl.build(:voice)]
131
127
 
132
128
  node_voice_pairs = node.voiced_as(voices)
133
129
  node_voice_pairs.size.should == 2
134
130
 
135
131
  node_voice_pairs.each do |pair|
136
- pair.should be_a(Node::Base::VoicedNode)
132
+ pair.should be_a(Node::Base::VoicedVersion)
137
133
  pair.node.should == node
138
134
  end
139
135
 
@@ -144,27 +140,18 @@ describe Node::Base do
144
140
 
145
141
  describe "definitions(klass)" do
146
142
  it "should be itself if it is an instance of the klass" do
147
- node = Node::Bar.new
148
- node.add Node::NoteSet.new
143
+ node = FactoryGirl.build(:bar)
144
+ node.add FactoryGirl.build(:note_set)
149
145
  node.should be_definition
150
146
 
151
147
  node.definitions(Node::Bar).should == [node]
152
148
  end
153
149
 
154
150
  it "should include descendants which are instances of klass" do
155
- node = Node::Base.new.tap do |base|
156
- base.add(
157
- Node::Bar.new.tap do |bar|
158
- bar.add Node::NoteSet.new
159
- end
160
- )
161
-
162
- base.add(
163
- Node::Bar.new.tap do |bar|
164
- bar.add Node::NoteSet.new
165
- end
166
- )
167
- end
151
+ node = FactoryGirl.build(:base, :children => [
152
+ FactoryGirl.build(:bar, :children => [FactoryGirl.build(:note_set)]),
153
+ FactoryGirl.build(:bar, :children => [FactoryGirl.build(:note_set)])
154
+ ])
168
155
 
169
156
  node.definitions(Node::Bar).should have(2).bars
170
157
  end
@@ -172,17 +159,17 @@ describe Node::Base do
172
159
 
173
160
  describe "root" do
174
161
  it "should be itself if it has no parent" do
175
- node = Node::Base.new
162
+ node = FactoryGirl.build(:base)
176
163
  node.root.should == node
177
164
  end
178
165
 
179
166
  it "should be the ancentor of the node which has no parent of its own" do
180
- note_set = Node::NoteSet.new
167
+ note_set = FactoryGirl.build(:note_set)
181
168
 
182
- bar = Node::Bar.new
169
+ bar = FactoryGirl.build(:bar)
183
170
  bar.add note_set
184
171
 
185
- root = Node::Base.new
172
+ root = FactoryGirl.build(:base)
186
173
  root.add bar
187
174
 
188
175
  note_set.root.should == root
@@ -191,55 +178,53 @@ describe Node::Base do
191
178
 
192
179
  describe "name" do
193
180
  it "should be the given name, if available" do
194
- Node::Bar.new(:name => :Intro).name.should == :Intro
181
+ FactoryGirl.build(:bar, :name => :Intro).name.should == :Intro
195
182
  end
196
183
 
197
184
  it "should be based on the parent's name the node's class and id, if not available" do
198
- child = Node::NoteSet.new
199
- bar = Node::Bar.new(:name => :Intro).tap do |bar|
200
- bar.add child
201
- end
185
+ child = FactoryGirl.build(:note_set)
186
+ bar = FactoryGirl.build(:bar, :name => :Intro, :children => [child])
202
187
 
203
188
  child.name.should == "IntroNoteSetOne"
204
189
  end
205
190
 
206
191
  it "should be based on the node's class and id, if there's no parent and the there's no given name" do
207
- child = Node::NoteSet.new
192
+ child = FactoryGirl.build(:note_set)
208
193
  child.name.should == "NoteSetOne"
209
194
  end
210
195
  end
211
196
 
212
197
  describe "id" do
213
198
  it "should be 1 by default" do
214
- child = Node::NoteSet.new
199
+ child = FactoryGirl.build(:note_set)
215
200
  child.id.should == 1
216
201
  end
217
202
  end
218
203
 
219
204
  describe "id_as_word" do
220
205
  it "should camelize if necessary" do
221
- node = Node::Base.new(:id => 24)
206
+ node = FactoryGirl.build(:base, :id => 24)
222
207
  node.id_as_word.should == "TwentyFour"
223
208
  end
224
209
  end
225
210
 
226
211
  describe "definition_name" do
227
212
  it "should turn the name to a lilypond acceptable name" do
228
- node = Node::Base.new(:name => "Verse 1 line-2")
213
+ node = FactoryGirl.build(:base, :name => "Verse 1 line-2")
229
214
  node.definition_name.should == "VerseOneLineTwo"
230
215
  end
231
216
  end
232
217
 
233
218
  describe "descendants(klass)" do
234
219
  it "should be itself if it is an instance of the klass" do
235
- tab = Node::Tab.new(:children => [Node::Bar.new])
220
+ tab = FactoryGirl.build(:tab, :children => [FactoryGirl.build(:bar)])
236
221
  tab.descendants(Node::Tab).should == [tab]
237
222
  end
238
223
 
239
224
  it "should include descendants which are instances of klass" do
240
- tab = Node::Tab.new(:children => [
241
- Node::Bar.new(:name => :Intro, :children => [
242
- Node::NoteSet.new
225
+ tab = FactoryGirl.build(:tab, :children => [
226
+ FactoryGirl.build(:bar, :name => :Intro, :children => [
227
+ FactoryGirl.build(:note_set)
243
228
  ])
244
229
  ])
245
230
 
@@ -247,17 +232,15 @@ describe Node::Base do
247
232
  end
248
233
 
249
234
  it "should follow the definitions of node references for descendants" do
250
- tab = Node::Tab.new(:children => [
251
- Node::Bar.new(:name => :Intro, :children => [
252
- Node::NoteSet.new
253
- ]),
235
+ tab = FactoryGirl.build(:tab, :children => [
236
+ FactoryGirl.build(:bar, :name => :Intro, :children => [FactoryGirl.build(:note_set)]),
254
237
 
255
- Node::Line.new(:name => 'Line 1', :children => [
256
- Node::Bar.new(:name => :Intro)
238
+ FactoryGirl.build(:line, :name => 'Line 1', :children => [
239
+ FactoryGirl.build(:bar, :name => :Intro , :children => [])
257
240
  ]),
258
241
 
259
- Node::Stanza.new(:children => [
260
- Node::Line.new(:name => 'Line 1')
242
+ FactoryGirl.build(:stanza, :children => [
243
+ FactoryGirl.build(:line, :name => 'Line 1', :children => [])
261
244
  ])
262
245
  ])
263
246
 
@@ -270,9 +253,34 @@ describe Node::Base do
270
253
 
271
254
  describe "chorded" do
272
255
  it "should return the chorded version of the node" do
273
- node = Node::ChordSet.new
274
- chorded_node = node.chorded
275
- chorded_node.node.should == node
256
+ node = FactoryGirl.build(:base)
257
+ chorded_version = node.chorded
258
+ chorded_version.node.should == node
259
+ chorded_version.should be_a(Node::Base::ChordedVersion)
260
+ end
261
+ end
262
+
263
+ describe "stanza_version" do
264
+ it "should be a stanza version of the node" do
265
+ node = FactoryGirl.build(:base)
266
+ stanza_version = node.stanza_version
267
+ stanza_version.node.should == node
268
+ stanza_version.should be_a(Node::Base::StanzaVersion)
269
+ end
270
+ end
271
+
272
+ describe "ancestor(node_class)" do
273
+ it "should be the first ancestor of the node matching the node class" do
274
+ bar = FactoryGirl.build(:bar)
275
+ line = FactoryGirl.build(:line, :name => 'Intro', :children => [bar])
276
+ stanza = FactoryGirl.build(:stanza, :name => 'Intro', :children => [line])
277
+
278
+ bar.ancestor(Node::Stanza).should == stanza
279
+ end
280
+
281
+ it "should be nil if there is no ancestor matching the node class" do
282
+ bar = FactoryGirl.build(:bar)
283
+ bar.ancestor(Node::Stanza).should be_nil
276
284
  end
277
285
  end
278
286
  end