03 Aug 2013, 14:23
Linkedin profile_pragsmall

Gavin Thomas (3 posts)

After going through the Iteration D3 section of the book, I’ve now run

> rake test test/controllers/line_items_controller_test.rb

expecting the tests to pass. However, a number of them are failing. I’m going to investigate now and attempt to fix myself. However I want to raise this as an issue with the book because it doesn’t appear to be working. Please let me know if this is just a typo on my side, but as far as I can see, I don’t think it is.

Errors raised

» rake test test/controllers/line_items_controller_test.rb
Run options: --seed 28131

# Running tests:

EEEEEEE

Finished tests in 0.152175s, 45.9997 tests/s, 0.0000 assertions/s.

  1) Error:
LineItemsControllerTest#test_should_create_line_item:
RuntimeError: @controller is nil: make sure you set it in your test's setup method.
    test/controllers/line_items_controller_test.rb:21:in `block (2 levels) in <class:LineItemsControllerTest>'
    test/controllers/line_items_controller_test.rb:20:in `block in <class:LineItemsControllerTest>'

  2) Error:
LineItemsControllerTest#test_should_destroy_line_item:
AbstractController::ActionNotFound: The action 'destroy' could not be found for LineItemsController
    test/controllers/line_items_controller_test.rb:44:in `block (2 levels) in <class:LineItemsControllerTest>'
    test/controllers/line_items_controller_test.rb:43:in `block in <class:LineItemsControllerTest>'

  3) Error:
LineItemsControllerTest#test_should_get_edit:
ActionView::Template::Error: First argument in form cannot contain nil or be empty
    app/views/line_items/_form.html.erb:1:in `_app_views_line_items__form_html_erb__4281858416148963396_70361385201780'
    app/views/line_items/edit.html.erb:3:in `_app_views_line_items_edit_html_erb__4020584813906169161_70361384882960'
    test/controllers/line_items_controller_test.rb:33:in `block in <class:LineItemsControllerTest>'

  4) Error:
LineItemsControllerTest#test_should_get_index:
ActionView::Template::Error: undefined method `each' for nil:NilClass
    app/views/line_items/index.html.erb:15:in `_app_views_line_items_index_html_erb___3566547294755704136_70361385581340'
    test/controllers/line_items_controller_test.rb:9:in `block in <class:LineItemsControllerTest>'

  5) Error:
LineItemsControllerTest#test_should_get_new:
ActionView::Template::Error: First argument in form cannot contain nil or be empty
    app/views/line_items/_form.html.erb:1:in `_app_views_line_items__form_html_erb__4281858416148963396_70361385201780'
    app/views/line_items/new.html.erb:3:in `_app_views_line_items_new_html_erb___314267739356437749_70361409515040'
    test/controllers/line_items_controller_test.rb:15:in `block in <class:LineItemsControllerTest>'

  6) Error:
LineItemsControllerTest#test_should_show_line_item:
ActionView::Template::Error: undefined method `product' for nil:NilClass
    app/views/line_items/show.html.erb:5:in `_app_views_line_items_show_html_erb___3960064229001787208_70361409679260'
    test/controllers/line_items_controller_test.rb:28:in `block in <class:LineItemsControllerTest>'

  7) Error:
LineItemsControllerTest#test_should_update_line_item:
AbstractController::ActionNotFound: The action 'update' could not be found for LineItemsController
    test/controllers/line_items_controller_test.rb:38:in `block in <class:LineItemsControllerTest>'

7 tests, 0 assertions, 0 failures, 7 errors, 0 skips

** Code **

If you visit my GitHub repo, you can see the state of the code as per end of Iteration D2. This is on the master branch, delivered as commit https://github.com/Ippoippo/agile-web-development-with-rails-depot/commit/5a703963b10092d5ef1c77cd78b4adfd69c60f5c

The code edited as per Iteration D3 is on the Iteration_D3 branch in the repo. I’ve uploaded the code via commit https://github.com/Ippoippo/agile-web-development-with-rails-depot/commit/bbb236d3121e90a6430a7ce4059c0b511a556966

16 Aug 2013, 02:44
Linkedin profile_pragsmall

Gavin Thomas (3 posts)

Now coming back to look at this issue again, and spotted one problem. My mistake, but annoying that there were no tests in place to pick up this mistake after I wrote it back in Iteration D1. I’d accidentally called “/app/controllers/concerns/current_cart.rb” current_card.rb instead, which meant include CurrentCart in the Line Items controller was failing.

So, one failure left now

Finished tests in 0.190573s, 36.7313 tests/s, 52.4733 assertions/s.

  1) Error:
LineItemsControllerTest#test_should_create_line_item:
NoMethodError: undefined method `id' for nil:NilClass
    app/controllers/concerns/current_cart.rb:8:in `rescue in set_cart'
    app/controllers/concerns/current_cart.rb:6:in `set_cart'
    test/controllers/line_items_controller_test.rb:21:in `block (2 levels) in <class:LineItemsControllerTest>'
    test/controllers/line_items_controller_test.rb:20:in `block in <class:LineItemsControllerTest>'

7 tests, 10 assertions, 0 failures, 1 errors, 0 skips
17 Aug 2013, 06:36
Linkedin profile_pragsmall

Gavin Thomas (3 posts)

Resolved… consider this issue resolved.

My mistake again

My CurrentCart module had

@cart = Cart.create session[:cart_id] = @cart.id

not

@cart = Cart.create
session[:cart_id] = @cart.id
  You must be logged in to comment