quotes spec says one thing, tests another #2

Closed
jessegoodnoe opened this Issue Nov 2, 2011 · 4 comments

3 participants

@jessegoodnoe

This quotes_spec.rb test:

  it "should return an empty list of results" do
    subject[3].should == "Could not find a quote at this time"
    subject.find(3).should == "Could not find a quote at this time"
  end

Tests that it returns "Could not find a quote at this time", not []. Which should it be?

@mungruby
UW Professional and Continuing Education Ruby Certificate member

"Could not find a quote at this time"

@jessegoodnoe

So by that logic, given the expectation below, some_method should be returning 2?

it "some_method returns 1" do
subject.some_method.should == 2
end

@mungruby
UW Professional and Continuing Education Ruby Certificate member

Well, what I can tell you is that is how to get the examples to pass :). This particular case is not the only example in the spec file that depends upon the return value matching a particular string. See also:

describe "::missing_quote" do
  it "should allow you to set the message when a quote is missing" do
    expected_quote = "All of our quotes have gone missing"
    Quotes.missing_quote = expected_quote

    quotes = Quotes.load("FILE_DOES_NOT_EXIST")
    quotes[3].should == expected_quote
  end
end

Typically, when you access a a collection using the [] syntax, you expect to get back a single item, not an array of items. If the index does not exist you would get nil. The same can be said for using the find method.

http://ruby-doc.org/core-1.9.2/Array.html#method-i-5B-5D

http://ruby-doc.org/core-1.9.2/Enumerable.html#method-i-find

@burtlo burtlo was assigned Nov 4, 2011
@burtlo
UW Professional and Continuing Education Ruby Certificate member

@jessegoodnoe the definition text is misleading and the expectations are right. I will adjust them.

@burtlo burtlo closed this in 0743b0f Nov 6, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment