How to dump contents produced during spec evaluation?

In a story, I have the following happening:
post("/resources/", ‘resource’ => request_attrs)
response.should render_template(‘resource/new’)
response.should have_tag(’*’, /must have one or more X defined/)

In the ResourceController spec, I have the following happening:
post( :create, :resource => request_attrs )
response.should render_template(‘resource/new’)
response.should have_tag(’*’, /must have one or more X defined/)

The problem I’m having is that the story works just fine, but the
spec claims that there are no tags matching ‘*’ in the response.

Is there any way I can dump the contents of the response, in the hope
that they might tip me off as to the cause of this error?

I’ve checked the stories, and I do not have any steps with the same
description as the one that passes in the story but fails in the
spec. I’ve stumbled across this before, especially where a step is
“when the user creates a new resource” - often the first one the
story runner sees will become the definition of “when the user
creates a new resource”, and later versions have to be renamed eg:
“when the user creates a new resource with special feature X”.
That’s not happening here as far as I can tell.

Any clues on where to start looking?

Thanks
Alex

On Sun, Feb 24, 2008 at 5:54 PM, Alex S. [email protected]
wrote:

The problem I’m having is that the story works just fine, but the
spec claims that there are no tags matching ‘*’ in the response.

Is there any way I can dump the contents of the response, in the hope
that they might tip me off as to the cause of this error?

puts response.body

On 25/02/2008, at 10:58 , David C. wrote:

On Sun, Feb 24, 2008 at 5:54 PM, Alex S.
[email protected] wrote:

In the ResourceController spec, I have the following happening:
post( :create, :resource => request_attrs )
response.should render_template(‘resource/new’)
response.should have_tag(‘*’, /must have one or more X defined/)

Is there any way I can dump the contents of the response, in the
hope
that they might tip me off as to the cause of this error?

puts response.body

Okay, this is weird. The result seems to indicate that the body of
the response is the literal text, “resource/new”:

My autotest results show (I’ve changed the name of the resource to
‘resource’):

script/spec:4:

Finished in 0.753821 seconds

25 examples, 1 failure

Time to go through all my other specs and check that they’re working
(or breaking) the same way, to see if I can figure out what I’ve done
wrong.

Alex

On Feb 24, 2008, at 4:29 PM, Alex S. wrote:

Okay, this is weird. The result seems to indicate that the body of
the response is the literal text, “resource/new”:

My autotest results show (I’ve changed the name of the resource to
‘resource’):

Try

puts response.class
puts response.inspect

to see whether you have what you think you do.

On Sun, Feb 24, 2008 at 6:29 PM, Alex S. [email protected]
wrote:

Is there any way I can dump the contents of the response, in the
hope
that they might tip me off as to the cause of this error?

puts response.body

Okay, this is weird. The result seems to indicate that the body of
the response is the literal text, “resource/new”:

Ah yes - of course.

Give this a read and see if it answers your question:

http://rspec.info/documentation/rails/writing/controllers.html

On 25/02/2008, at 11:42 , David C. wrote:

Steve - it’s because of isolation - I pointed Alex to the docs.

Yup, I’m having a low-caffeine day apparently. I’m going to great
pains to isolate just the portions of the controller that need to be
designed (using mocks and stubs), then slapping a test in there that
looks for an output that the mock will never generate.

The error message is already specced in the model spec and the view
spec, and it’s already checked for in the story - do I need more
testing for that failure path?

Alex

On Sun, Feb 24, 2008 at 6:35 PM, s.ross [email protected] wrote:

puts response.class
puts response.inspect

Steve - it’s because of isolation - I pointed Alex to the docs.