small medium large xlarge

Fableavatar_pragsmall
10 Aug 2011, 19:25
Ricardo Rodriguez (4 posts)

Hello,

I just started on the Ruby and Rails path, with the “Agile Web Development with Rails” book. I think I might have hit a snag, however,

During the section titled “Iteration C4: Functional Testing of Controllers,” I follow all the steps, or so I think, and I get this error when attempting to run the “rake test:functionals” command:

/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/rake_test_loader.rb:9:in `require': /Users/<user>/Development/depot/test/functional/
products_controller_test.rb:8: syntax error, unexpected tSYMBEG, expecting '}' (SyntaxError)
      :description => 'Wibbles are fun!'
       ^
/Users/<user>/Development/depot/test/functional/products_controller_test.rb:9: syntax error, unexpected tASSOC, expecting kEND
      :image_url   => 'lorem.jpg'
                     ^
/Users/<user>/Development/depot/test/functional/products_controller_test.rb:10: syntax error, unexpected tASSOC, expecting kEND
      :price       => 19.95
                     ^
/Users/<user>/Development/depot/test/functional/products_controller_test.rb:55: syntax error, unexpected $end, expecting kEND
        from /Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/rake_test_loader.rb:9
        from /Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/rake_test_loader.rb:9:in `each'
        from /Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/rake_test_loader.rb:9
        from /Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/rake_test_loader.rb:5:in `each'
        from /Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/rake_test_loader.rb:5
rake aborted!
Command failed with status (1): [/System/Library/Frameworks/Ruby.framework/...]

Now what confuses me is that I never “touched” this file during this section, i.e. products_controller_test.rb. When I test my unit tests, I’m fine. Here’s the products_controller_test.rb file:

require 'test_helper'

class ProductsControllerTest < ActionController::TestCase
  setup do
    @product = products(:one)
    @update = {
      :title       => 'Lorem Ipsum'
      :description => 'Wibbles are fun!'
      :image_url   => 'lorem.jpg'
      :price       => 19.95
    }
  end

  test "should get index" do
    get :index
    assert_response :success
    assert_not_nil assigns(:products)
  end

  test "should get new" do
    get :new
    assert_response :success
  end

  test "should create product" do
    assert_difference('Product.count') do
      post :create, :product => @update
    end

    assert_redirected_to product_path(assigns(:product))
  end

  test "should show product" do
    get :show, :id => @product.to_param
    assert_response :success
  end

  test "should get edit" do
    get :edit, :id => @product.to_param
    assert_response :success
  end

  test "should update product" do
    put :update, :id => @product.to_param, :product => @update
    assert_redirected_to product_path(assigns(:product))
  end

  test "should destroy product" do
    assert_difference('Product.count', -1) do
      delete :destroy, :id => @product.to_param
    end

    assert_redirected_to products_path
  end
end

I’m sure that there’s something very obvious that I’m missing. Please advise.

Face_pragsmall
13 Aug 2011, 19:07
Mads Ohm Larsen (1 post)

You are missing a comma after each string literal in your hash.

It should be: @update = { :title => 'Lorem Ipsum', :description => 'Wibbles are fun!', :image_url => 'lorem.jpg', :price => 19.95, }

You must be logged in to comment