Forum: Ruby on Rails Newbie going blind on test from book

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4710a8ada2adc162aaee4288d9879d8e?d=identicon&s=25 mailing (Guest)
on 2005-12-09 00:46
(Received via mailing list)
Hi all,

I'm working on the rails book and the test definition shown further
below
gives the following error.

test_read_with_hash(ProductTest):
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.[]
    test/unit/product_test.rb:45:in `test_read_with_hash'

4 tests, 15 assertions, 0 failures, 1 errors

  def test_read_with_hash
    assert_kind_of Product, @product
    vc_book = @products["version_control_book"]		<< line 45
    assert_equal vc_book["id"], @product.id
    assert_equal vc_book["title"], @product.title
    assert_equal vc_book["description"], @product.description
    assert_equal vc_book["image_url"], @product.image_url
    assert_equal vc_book["price"], @product.price
    assert_equal vc_book["date_available"],
@product.date_available_before_type_cast
  end

Fixture in question:

version_control_book:
  id:              1
  title:           Pragmatic Version Control
  description:     How to use version control
  image_url:       http://.../sk_svn_small.jpg
  price:           29.95
  date_available:  2005-01-26 00:00:00


I'm clueless .. Thanx a lot


Regards,

Gerard.

--
"Who cares if it doesn't do anything?  It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."

My $Grtz =~ Gerard;
~
:wq!
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 ara.t.howard (Guest)
on 2005-12-09 01:47
(Received via mailing list)
On Fri, 9 Dec 2005, Gerard wrote:

> 4 tests, 15 assertions, 0 failures, 1 errors
>
>  def test_read_with_hash
>    assert_kind_of Product, @product
>    vc_book = @products["version_control_book"]		<< line 45
                        ^
                        ^
                        ^
                        take this away

-a
--
===============================================================================
| ara [dot] t [dot] howard [at] noaa [dot] gov
| all happiness comes from the desire for others to be happy.  all misery
| comes from the desire for oneself to be happy.
| -- bodhicaryavatara
===============================================================================
4710a8ada2adc162aaee4288d9879d8e?d=identicon&s=25 mailing (Guest)
on 2005-12-09 09:59
(Received via mailing list)
Regretfully that wasn't it, althought the reply signs "> " had me
confused
somewhat I tried several. Removing any quotes or brackets results in
syntax
errors so that doesn't improve.

I also tried the @products in single form @product, but that still gets
the
error:

test_read_with_hash(ProductTest):
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.[]
    test/unit/product_test.rb:45:in `test_read_with_hash'

4 tests, 15 assertions, 0 failures, 1 errors

Regards,

Gerard.

On Friday 09 December 2005 01:43, ara.t.howard@noaa.gov tried to type
something like:
>                         take this away
>
> -a

--
"Who cares if it doesn't do anything?  It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."

My $Grtz =~ Gerard;
~
:wq!
This topic is locked and can not be replied to.