Rails rspec silently failing

I’ve been beating my head against this for a couple of hours now, and
I’m a bit frustrated, so I apologize in advance.

I’m trying to use rspec to test an order processing system, which uses
google checkout. The idea was to have a couple of orders in the
database in various stages, and hit the notifier interface to make
sure that everything transitioned to the right place. However, I
can’t get to this, because rspec seems to silently blow-up somewhere.
This code “passes”:

require File.dirname(FILE) + ‘/…/spec_helper’

describe OrdersController do
integrate_views
fixtures :orders

it “should set the right order amount” do
prepare_order_mock

 post "subscribe", {:sub_type => "1"}

 fail "This should throw an error"

end
end

It then returns: “0 examples, 0 failures”.

How is such a thing possible? This seems like a serious problem; I
would expect an exception from somewhere inside of the post, or the
fail message. Instead everything is green.

My only hypothesis is that since I’m creating an order object and
calling a bunch of methods on it and somehow that’s verbotten. The
docs mention suggests mocking domain objects – which seems if not
completely misguided at least seriously counter-intuitive – and
perhaps this has something to do with it. But silently imploding
seems more like a bug.

I should mention that the controller actually works in Real Life, but
I was trying to get a little piece of mind and work out all the
permutations in a test just to make sure. And failing silently is
worse than no testing at all.

Taking a few deep breaths,
-w

That seems more like rspec isn’t even finding it. What is the file name?
Is
it in a location that rspec is going to look for it?

-Corey

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. Either way the code runs
all the way through the action method. But if I call a method on the
Order, then it seems to just disappear after the controller returns.
Something is swallowing exceptions or something like that. It runs to
the end though, and I know it runs to the end because I put in puts
statements.

On Feb 5, 2008, at 7:54 PM, Corey H. wrote:

google checkout. The idea was to have a couple of orders in the

rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users


http://www.coreyhaines.com
The Internet’s Premiere source of information about Corey H.

Will Schenk
[email protected]
http://benchcoach.com/

http://menumap.monkeythumb.net/

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

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

$
GCHECKOUT_FRONTEND.should_receive(:create_checkout_command).and_return
{ @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 |
data|
@private_data = data
end

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

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.