small medium large xlarge

Generic-user-small
19 Jan 2012, 19:09
Gordon Agress (3 posts)

I’m in Ch. 11, Task F, and I’m getting this error:

test_should_create_line_item FAIL Expected response to be a redirect to http://test.host/carts/980190963 but was a redirect to http://test.host/ Assertion at /home/gordon/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.0/lib/action_dispatch/testing/assertions/response.rb:67:in `assert_redirected_to’

Rails 3.1, Ruby 1.9.2 (2011-02-18 revision 30909).

The download code for depot_l has exact same error. (That code also requires two adjustments to test without error. First, addition of « gem ‘minitest’ », in the group :test. Second, in app/views/layouts/application.html.erb, bracketing the <div> holding @cart with an <%= if . . . <%= end > block.)

Any suggestions?

Generic-user-small
19 Jan 2012, 22:23
Gordon Agress (3 posts)

Got it. After changing line_items_controller.rb to redirect to the store_url, the test line_items_controller_test.rb must also be changed.

In the latter, the test function “should create line item” should be revised so this line:

assert_redirected_to cart_path(assigns(:line_item).cart)

</code>

becomes this line:

assert_redirected_to store_url

</code>

With this change, and those above, depot_l runs without error and passes all tests.

Generic-user-small
19 Jan 2012, 23:07
Gordon Agress (3 posts)

Pushing on further, I see these iterations are not expected to pass tests, and the fix I’ve put in is offered later in the chapter. It would be better to note that in the text – some of us like to keep our tests passing, and we view test failure as a sign that something has gone wrong.

I’d also suggest that the text shouldn’t wait to get the tests to pass. If someone has a made a mistake, the test output should help them find that – and this is harder when there are other failures in the test.

You must be logged in to comment