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.