[rspec-users] stubbed methods are not returning what I've stubbed them to return

Dan Brooking dmbrooking at gmail.com
Sat Mar 16 12:56:52 UTC 2013

I'm working on a small Sintra app and am having trouble getting my stub to
return what I want it to.  I've been searching and found quite a few with
this question but no real answers.  I also posted this to the sinatrarb
google group in case it's an issue there.

I have a helper method that returns a random string. I'm hoping it's
something very simple I'm doing wrong

def random_string(length)
  (0..length).map{ rand(36).to_s(36) }.join

I have my test written as follows:

describe "#random_string" do
it "returns a random string" do


 str = random_string(6)
 str.should == "abcdef"

I have tried both lines shown in the code, and both times, the code runs.
 Yet my tests are still failing.  It doesn't look like the stub is taking.
My failure looks like:

#random_string returns a random string
     Failure/Error: str.should == "abcdef"
       expected: "abcdef"
            got: "xcz0g7a" (using ==)

Any ideas?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20130316/5b99d287/attachment.html>

More information about the rspec-users mailing list