[rspec-users] rails rspec silently failing

Will Schenk wschenk at gmail.com
Wed Feb 6 11:27:26 EST 2008

Ok I think I've figured out the command that makes rspec blow up.

I'm creating the mock object like this:
   def prepare_order_mock
     $GCHECKOUT_FRONTEND = mock "gcheckout"
     @co_cmd_mock = mock "checkout_command"
     @shopping_cart = mock "shopping cart"

     @private_data = nil

{ @co_cmd_mock }
     @co_cmd_mock.should_receive( "continue_shopping_url=" )
     @co_cmd_mock.should_receive( "shopping_cart", 2 ).and_return  
{ @shopping_cart }
     @shopping_cart.should_receive "create_item"
     @shopping_cart.should_receive( "private_data=" ).and_return do | 
       @private_data = data

@co_cmd_mock.should_receive( "send_to_google_checkout" ).and_return do
       res = mock( "result" )
       res.should_receive( "redirect_url" ).and_return{ "url string" }

Then when my code calls:

     command = $GCHECKOUT_FRONTEND.create_checkout_command
     command.continue_shopping_url = continue_url

The second line makes rspec silently blow up.  If I comment it out  
then it runs fine.

On Feb 6, 2008, at 12:58 AM, Hans de Graaff wrote:

> On Tue, 2008-02-05 at 23:50 -0500, Will Schenk wrote:
>> This is both running the file directly or using script/spec.  If I
>> leave the spec file as is, and I comment out a line
>> @order.send_order_to_google_checkout in the _controller_ then it runs
>> fine, i.e. it gets to the fail statement.
> Since you don't include the actual controller code it's a bit hard to
> help out here, but it's better form to just mock this code in your
> controller spec. You can then vary the different responses from the
> google checkout and see if your controller handles them correctly.
> The actual interaction with google checkout should be described with
> examples in the order_spec.rb file. Right now you are testing the  
> whole
> stack and it becomes very hard to track down what is going wrong
> exactly.
> Kind regards,
> Hans

More information about the rspec-users mailing list