# Pickaxe code error

**URL:** <https://rubytalk.org/t/pickaxe-code-error/28648>\
**Category:** ruby-talk\
**Created:** [5 July 2006 11:33 UTC](https://rubytalk.org/t/pickaxe-code-error/28648 "2006-07-05T11:33:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dark\_Ambient](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@Dark\_Ambient](https://rubytalk.org/u/Dark_Ambient)\
**Post date:** [5 July 2006 11:33 UTC](https://rubytalk.org/t/pickaxe-code-error/28648/1 "2006-07-05T11:33:27Z")

</div>

Not sure what's going on with some code in Programming Ruby, it's  
early on where a SongList container is being created and test units  
are run.  
I'm receiving this error:

&nbsp;&nbsp;1) Error:  
test\_delete(TestSongList):  
NameError: uninitialized constant TestSongList::Song  
&nbsp;&nbsp;&nbsp;&nbsp;pickaxe\_SongListContainer.rb:52:in `test\_delete'

the rb:52 won't be right as I've put notes in comments between the  
code, which I'm stripping here. Perhaps someone is familiar with  
example. I checked errata with no luck..TIA

require 'test/unit'

class SongList  
&nbsp;&nbsp;def initialize  
&nbsp;&nbsp;&nbsp;&nbsp;@songs = Array.new  
&nbsp;&nbsp;end

&nbsp;&nbsp;def append(song)  
&nbsp;&nbsp;&nbsp;&nbsp;#songs.push(song)  
&nbsp;&nbsp;&nbsp;&nbsp;self  
&nbsp;&nbsp;end

&nbsp;&nbsp;def delete\_first  
&nbsp;&nbsp;&nbsp;&nbsp;@songs.shift  
&nbsp;&nbsp;end

&nbsp;&nbsp;def delete\_last  
&nbsp;&nbsp;&nbsp;&nbsp;@songs.pop  
&nbsp;&nbsp;end

&nbsp;&nbsp;def [](index)  
&nbsp;&nbsp;&nbsp;&nbsp;@songs[index]  
&nbsp;&nbsp;end  
end

class TestSongList \< Test::Unit::TestCase  
&nbsp;&nbsp;def test\_delete  
&nbsp;&nbsp;&nbsp;&nbsp;list = SongList.new  
&nbsp;&nbsp;&nbsp;&nbsp;s1 = Song.new('title1', 'artist1', 1)  
&nbsp;&nbsp;&nbsp;&nbsp;s2 = Song.new('title2', 'artist2', 2)  
&nbsp;&nbsp;&nbsp;&nbsp;s3 = Song.new('title3', 'artist3', 3)  
&nbsp;&nbsp;&nbsp;&nbsp;s4 = Song.new('title4', 'artist4', 4)

&nbsp;&nbsp;&nbsp;&nbsp;list.append(s1).append(s2).append(s3).append(s4)

&nbsp;&nbsp;&nbsp;&nbsp;assert\_equal(s1, list[0])  
&nbsp;&nbsp;&nbsp;&nbsp;assert\_equal(s3, list[2])  
&nbsp;&nbsp;&nbsp;&nbsp;assert\_nil(list[9])

&nbsp;&nbsp;&nbsp;&nbsp;assert\_equal(s1, list.delete\_first)  
&nbsp;&nbsp;&nbsp;&nbsp;assert\_equal(s2, list.delete\_first)  
&nbsp;&nbsp;&nbsp;&nbsp;assert\_equal(s4, list.delete\_last)  
&nbsp;&nbsp;&nbsp;&nbsp;assert\_equal(s3, list.delete\_last)  
&nbsp;&nbsp;&nbsp;&nbsp;assert\_nil(list.delete\_last)  
&nbsp;&nbsp;end  
end

---

<div class="post-metadata">

**Author:** ![Dark\_Ambient](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@Dark\_Ambient](https://rubytalk.org/u/Dark_Ambient)\
**Post date:** [5 July 2006 11:37 UTC](https://rubytalk.org/t/pickaxe-code-error/28648/2 "2006-07-05T11:37:59Z")

</div>

Just realized that this needed to be in with the rest of the previous  
jukebox code.  
Sorry - ignore.

Stuart

> **···**
>
> On 7/5/06, Dark Ambient \<sambient@gmail.com\> wrote:
> 
> > Not sure what's going on with some code in Programming Ruby, it's  
> > early on where a SongList container is being created and test units  
> > are run.  
> > I'm receiving this error:
> > 
> > &nbsp;&nbsp;1) Error:  
> > test\_delete(TestSongList):  
> > NameError: uninitialized constant TestSongList::Song  
> > &nbsp;&nbsp;&nbsp;&nbsp;pickaxe\_SongListContainer.rb:52:in `test\_delete'
> > 
> > the rb:52 won't be right as I've put notes in comments between the  
> > code, which I'm stripping here. Perhaps someone is familiar with  
> > example. I checked errata with no luck..TIA
> > 
> > require 'test/unit'
> > 
> > class SongList  
> > &nbsp;&nbsp;def initialize  
> > &nbsp;&nbsp;&nbsp;&nbsp;@songs = Array.new  
> > &nbsp;&nbsp;end
> > 
> > &nbsp;&nbsp;def append(song)  
> > &nbsp;&nbsp;&nbsp;&nbsp;#songs.push(song)  
> > &nbsp;&nbsp;&nbsp;&nbsp;self  
> > &nbsp;&nbsp;end
> > 
> > &nbsp;&nbsp;def delete\_first  
> > &nbsp;&nbsp;&nbsp;&nbsp;@songs.shift  
> > &nbsp;&nbsp;end
> > 
> > &nbsp;&nbsp;def delete\_last  
> > &nbsp;&nbsp;&nbsp;&nbsp;@songs.pop  
> > &nbsp;&nbsp;end
> > 
> > &nbsp;&nbsp;def (index)  
> > &nbsp;&nbsp;&nbsp;&nbsp;@songs[index]  
> > &nbsp;&nbsp;end  
> > end
> > 
> > class TestSongList \< Test::Unit::TestCase  
> > &nbsp;&nbsp;def test\_delete  
> > &nbsp;&nbsp;&nbsp;&nbsp;list = SongList.new  
> > &nbsp;&nbsp;&nbsp;&nbsp;s1 = Song.new('title1', 'artist1', 1)  
> > &nbsp;&nbsp;&nbsp;&nbsp;s2 = Song.new('title2', 'artist2', 2)  
> > &nbsp;&nbsp;&nbsp;&nbsp;s3 = Song.new('title3', 'artist3', 3)  
> > &nbsp;&nbsp;&nbsp;&nbsp;s4 = Song.new('title4', 'artist4', 4)
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;list.append(s1).append(s2).append(s3).append(s4)
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;assert\_equal(s1, list[0])  
> > &nbsp;&nbsp;&nbsp;&nbsp;assert\_equal(s3, list[2])  
> > &nbsp;&nbsp;&nbsp;&nbsp;assert\_nil(list[9])
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;assert\_equal(s1, list.delete\_first)  
> > &nbsp;&nbsp;&nbsp;&nbsp;assert\_equal(s2, list.delete\_first)  
> > &nbsp;&nbsp;&nbsp;&nbsp;assert\_equal(s4, list.delete\_last)  
> > &nbsp;&nbsp;&nbsp;&nbsp;assert\_equal(s3, list.delete\_last)  
> > &nbsp;&nbsp;&nbsp;&nbsp;assert\_nil(list.delete\_last)  
> > &nbsp;&nbsp;end  
> > end

---

<div class="post-metadata">

**Author:** ![Dark\_Ambient](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@Dark\_Ambient](https://rubytalk.org/u/Dark_Ambient)\
**Post date:** [5 July 2006 12:22 UTC](https://rubytalk.org/t/pickaxe-code-error/28648/3 "2006-07-05T12:22:02Z")

</div>

Back again on this one, still getting a test delete failure.  
1) Failure:  
test\_delete(TestSongList) [pickaxe\_p23.rb:137]:  
\<#\<Song:0x28a2d58 @artist="artist1", @duration=1, @name="title1"\>\>  
expected but was  
\<nil\>.

Not sure what this means exactly?

Anyone else have this issue or remember the section of the book ?

Stuart

1 tests, 1 assertions, 1 failures, 0 errors

> **···**
>
> On 7/5/06, Dark Ambient \<sambient@gmail.com\> wrote:
> 
> > Just realized that this needed to be in with the rest of the previous  
> > jukebox code.  
> > Sorry - ignore.
> > 
> > Stuart
> > 
> > On 7/5/06, Dark Ambient \<sambient@gmail.com\> wrote:  
> > \> Not sure what's going on with some code in Programming Ruby, it's  
> > \> early on where a SongList container is being created and test units  
> > \> are run.  
> > \> I'm receiving this error:  
> > \>  
> > \> 1) Error:  
> > \> test\_delete(TestSongList):  
> > \> NameError: uninitialized constant TestSongList::Song  
> > \> pickaxe\_SongListContainer.rb:52:in `test\_delete'  
> > \>  
> > \> the rb:52 won't be right as I've put notes in comments between the  
> > \> code, which I'm stripping here. Perhaps someone is familiar with  
> > \> example. I checked errata with no luck..TIA  
> > \>  
> > \> require 'test/unit'  
> > \>  
> > \> class SongList  
> > \> def initialize  
> > \> @songs = Array.new  
> > \> end  
> > \>  
> > \> def append(song)  
> > \> #songs.push(song)  
> > \> self  
> > \> end  
> > \>  
> > \> def delete\_first  
> > \> @songs.shift  
> > \> end  
> > \>  
> > \> def delete\_last  
> > \> @songs.pop  
> > \> end  
> > \>  
> > \> def (index)  
> > \> @songs[index]  
> > \> end  
> > \> end  
> > \>  
> > \> class TestSongList \< Test::Unit::TestCase  
> > \> def test\_delete  
> > \> list = SongList.new  
> > \> s1 = Song.new('title1', 'artist1', 1)  
> > \> s2 = Song.new('title2', 'artist2', 2)  
> > \> s3 = Song.new('title3', 'artist3', 3)  
> > \> s4 = Song.new('title4', 'artist4', 4)  
> > \>  
> > \> list.append(s1).append(s2).append(s3).append(s4)  
> > \>  
> > \> assert\_equal(s1, list[0])  
> > \> assert\_equal(s3, list[2])  
> > \> assert\_nil(list[9])  
> > \>  
> > \> assert\_equal(s1, list.delete\_first)  
> > \> assert\_equal(s2, list.delete\_first)  
> > \> assert\_equal(s4, list.delete\_last)  
> > \> assert\_equal(s3, list.delete\_last)  
> > \> assert\_nil(list.delete\_last)  
> > \> end  
> > \> end  
> > \>

---

<div class="post-metadata">

**Author:** ![Chris16](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@Chris16](https://rubytalk.org/u/Chris16)\
**Post date:** [5 July 2006 14:09 UTC](https://rubytalk.org/t/pickaxe-code-error/28648/4 "2006-07-05T14:09:35Z")

</div>

stuart fellowes wrote:

> Back again on this one, still getting a test delete failure.  
> 1) Failure:  
> test\_delete(TestSongList) [pickaxe\_p23.rb:137]:  
> \<#\<Song:0x28a2d58 @artist="artist1", @duration=1, @name="title1"\>\>  
> expected but was  
> \<nil\>.
> 
> Not sure what this means exactly?
> 
> Anyone else have this issue or remember the section of the book ?
> 
> Stuart
> 
> 1 tests, 1 assertions, 1 failures, 0 errors

you have the following:  
def append(song)  
&nbsp;&nbsp;&nbsp;&nbsp;#songs.push(song)  
&nbsp;&nbsp;&nbsp;&nbsp;self  
&nbsp;&nbsp;end

Note that the line to push the song onto the list is commented out.  
Looks like you hit # instead of @

cheers

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Dark\_Ambient](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@Dark\_Ambient](https://rubytalk.org/u/Dark_Ambient)\
**Post date:** [5 July 2006 14:24 UTC](https://rubytalk.org/t/pickaxe-code-error/28648/5 "2006-07-05T14:24:41Z")

</div>

Yep, that was the error! Thank you...much obliged!

Stuart

> **···**
>
> On 7/5/06, Chris Hulan \<hulachr@hotmail.com\> wrote:
> 
> > stuart fellowes wrote:  
> > \> Back again on this one, still getting a test delete failure.  
> > \> 1) Failure:  
> > \> test\_delete(TestSongList) [pickaxe\_p23.rb:137]:  
> > \> \<#\<Song:0x28a2d58 @artist="artist1", @duration=1, @name="title1"\>\>  
> > \> expected but was  
> > \> \<nil\>.  
> > \>  
> > \> Not sure what this means exactly?  
> > \>  
> > \> Anyone else have this issue or remember the section of the book ?  
> > \>  
> > \> Stuart  
> > \>  
> > \> 1 tests, 1 assertions, 1 failures, 0 errors
> > 
> > you have the following:  
> > def append(song)  
> > &nbsp;&nbsp;&nbsp;&nbsp;#songs.push(song)  
> > &nbsp;&nbsp;&nbsp;&nbsp;self  
> > &nbsp;&nbsp;end
> > 
> > Note that the line to push the song onto the list is commented out.  
> > Looks like you hit # instead of @
> > 
> > cheers
> > 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
