I was able to figure it out... for some reason my question was double
posted.

Thanks


On Sat, Mar 16, 2013 at 2:12 PM, Antonio Antillon <[email protected]>wrote:

> I think it's because you're are telling your method to select randomly and
> sequentially. That's why you get different string values than what you
> expect in your spec.
>
> Here:
> (0..length).map{ rand(36).to_s(36) }.join
>
> you're are taking random values and then joining them.. with random
> selected values, it's pretty unusual that you'll get back an ordered
> sequential string like "abcdef".
>
> Hope this helps.
>
>
> On Sat, Mar 16, 2013 at 5:53 AM, Dan Brooking <[email protected]>wrote:
>
>> I have a small Sinatra app I've been working on... I've been searching
>> and found quite a few with this question but no real answers.  I also
>> posted this to the Sinatra group in case it's an issue there. I'm hoping
>> it's something small that I'm doing wrong as I'm not too experienced in the
>> art of stubbing.
>>
>> I have a helper method that returns a random string...
>>
>> def random_string(length)
>>   (0..length).map{ rand(36).to_s(36) }.join
>> end
>>
>>
>> I have my test written as follows:
>>
>> describe "#random_string" do
>> it "returns a random string" do
>>
>> #Sinatra::Application.any_instance.stub(:random_string).and_return("abcdef")
>>
>> Sinatra::Application.should_receive(:random_string).with(6).and_return('abcdef')
>>  str = random_string(6)
>> str.should == "abcdef"
>> end
>>  end
>>
>>
>> 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?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "rspec" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/rspec/-/ZNjjVJxF9f4J.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "rspec" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to