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 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?
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users