[rspec-users] another noob question about stubs

Hans de Graaff hans at degraaff.org
Tue May 6 01:03:11 EDT 2008


On Wed, 2008-04-30 at 11:26 -0500, Patrick Aljord wrote:

> My spec looks like this:
>   it "should login with openid and redirect" do
>     openid_url = "patcito.myopenid.com"
>     controller.stub!(:using_open_id?).and_return(true)
>     controller.stub!(:authenticate_with_open_id).and_yield(result,openid_url,registration={"nickname"=>"patcito","email"=>"bob at gmail.com","fullname"=>'bobby
> bob'})
>     post :create, :openid_url => openid_url
>     session[:user_id].should_not be(nil)
>     response.should be_redirect
>   end

result is not defined, so the successful? method isn't known. I'd create
a mock for it and stub! that method.

result = mock('openid result')
result.stub!(:successful?).and_return(true)

You can then use result.should_receive(:successful?) in subsequent specs
to describe what happens if the result of the call is and isn't
successful.

Kind regards,

Hans
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080506/56c3f208/attachment.bin>


More information about the rspec-users mailing list