Beginning Ruby on Rails E-Commerce : Errata Help

Page 94, chapter 3, running $ ruby test/integration/book_test.rb
gives:

Expected response to be a <:redirect>, but was <500>

Does anyone know how to fix this problem? TIA.

Anyone figure this out? I get:
Expected response to be a <:redirect>, but was <200>

n.

Bala P. wrote:

Page 94, chapter 3, running $ ruby test/integration/book_test.rb
gives:

Expected response to be a <:redirect>, but was <500>

Does anyone know how to fix this problem? TIA.

Following table might help:

*  :success (status code is 200)
* :redirect (status code is within 300..399)
* :missing (status code is 404)
* :error (status code is within 500..599)
* any number (to specifically reference a particular status code)

assert_response :success # page rendered ok
assert_response :redirect # we’ve been redirected
assert_response :missing # not found
assert_response 505 # status code was 505

For more check out: Peak Obsession

You may also want to use curl on the command line to see the response
from the server. It also helps to write assert_tag and other
assertions.

Finally solved this mystery -

The first problem was that the newly created book wasn’t being saved, so
the ‘new’ page was being displayed instead of ‘create’. The cause of
this was the date. When I changed

:published_at => Time.now

to

:published_at => ‘2006-11-01’

then things were saved correctly and we ended up on the correct page.

Next problem was that assert_tag wasn’t passing, even though I could see
the new book in the raw html. On
http://wiki.marklunds.com/index.php?title=Test_Driven_Development_with_Ruby
I found that assert_tag doesn’t work with integration tests unless you
make this change in test_process.rb

 def html_document
  •  @html_document ||= HTML::Document.new(@response.body)
    
  •  HTML::Document.new(@response.body)
    
    end

Once I changed that then the integration test passed no problem.

Nick.

Bala P. wrote:

Following table might help:

*  :success (status code is 200)
* :redirect (status code is within 300..399)
* :missing (status code is 404)
* :error (status code is within 500..599)
* any number (to specifically reference a particular status code)

assert_response :success # page rendered ok
assert_response :redirect # we’ve been redirected
assert_response :missing # not found
assert_response 505 # status code was 505

For more check out: Peak Obsession

You may also want to use curl on the command line to see the response
from the server. It also helps to write assert_tag and other
assertions.

Cool. That solves the problem that I was having with my project. I
will try it out.

I was baffled, when I do curl I see the right page but when I do
assert_tag it bombs out!

On page 77, there is a test_destroy method that fails on assert_tag

assert_tag :tag => ‘div’,
:attributes => {:id => ‘notice’},
:content => ‘Successfully deleted author Joel Spolsky’

I am on Rails 1.2 and the assert_tag has been deprecated. The test was
failing so I used assert_select tag:

assert_select “div#notice”, ‘Successfully deleted author Joel Spolsky’

Bala P. wrote:

I was baffled, when I do curl I see the right page but when I do
assert_tag it bombs out!

I used tail -f log/test.log to see exactly what was happening in there.

n.