Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6546437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:42:28+00:00 2026-05-25T11:42:28+00:00

I’m working on this Exercise 49 in Learn Ruby the Hard Way The exercise

  • 0

I’m working on this Exercise 49 in Learn Ruby the Hard Way

The exercise asks to write a unit test for each function provided. One of the unit tests I am writing is giving me an error.

Here is the code I am testing (word_list is an array of Pair structs)

Pair = Struct.new(:token, :word)

def peek(word_list)
    begin
        word_list.first.token
    rescue
        nil
    end
end

def match(word_list, expecting)
    begin
        word = word_list.shift
        if word.token == expecting
            word
        else
            nil
        end
    rescue
        nil
    end
end

def skip(word_list, token)
    while peek(word_list) == token
        match(word_list, token)
    end
end

Here is the test:

def test_skip
    small_list = [Pair.new(:verb, 'go'), Pair.new(:verb, 'do')]
    skip(small_list, :verb)
    assert_equal([],small_list) 
end

Here is the error I get when I run the unit test:

  1) Error:
test_skip(SentenceTests):
TypeError: backtrace must be Array of String
    test_sentence.rb:23:in `test_skip'

In this case, line 23 refers to “skip(small_list, :verb)”. I am not sure why this error is happening, the above two functions were unit tested as well and those tests came out fine.

@Zabba, I did put them exactly as specified in the exercise above:

class ParserError < Exception

end

If anyone needs to see the exact files I am using here is the link to a gist:
https://gist.github.com/1190148

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:42:28+00:00Added an answer on May 25, 2026 at 11:42 am

    The line

    skip(small_list, :verb)
    

    makes your test skip through the whole list (2 verbs). Finally, it is empty.
    So small_list.firstis nil which has no method/field word.

    I get the error

    undefined method `word' for nil:NilClass (NoMethodError)
    

    though.

    Probably in your code this exception is caught by some other code which itself raises the exception you are seeing.

    UPDATE

    It turns out in Ruby 1.9’s test/unit (more specifically in the minitest/unit it is based on), there is a method skip which collides with your skip. See minitest/unit.rb, line 610. That method raised the exception because it expected its 2nd parameter to be an array.

    Just rename your skip.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.