Unit testing diffculty

ok, let me show you my “products” fixtures file:

ram:
  id: 1
  title:        RAM
  description:  ECC RAM Registered, 512MB
  image_url:    images/test.jpg
  price:        29.95
  date_available: 2005-01-25 00:00:00
busted_arsehole:
  id: 2
  title:        Busted Arsehole
  description:  I have an arsehole, it is-e busted
  image_url:    images/test.jpg
  price:        999.95
  date_available: 2005-01-25 00:00:00
hey:
  id: 3
  title:        hey
  description:  testinggggg
  image_url:    images/test.jpg
  price:        999.95
  date_available: 2007-01-25 00:00:00

The problem im facing is that for some reason instance variables @john,
@busted_arsehole, @ram are all nil(and according to the book im using
they should be associated with the particular fixtures. Otherwise unit
testing is working fine.

Any ideas?

Petr,

Try products(:ram) instead of @ram

Zack

Zack C. wrote:

Petr,

Try products(:ram) instead of @ram

Zack

Thanks, that did the trick. I suppose at the time the book was written
they were using a different version of rails. By the way, one of the
examples in the book is (simplified from my memory)

@product = Product.find(1)

localvariable = @products["ram"]

assert_equal(localvariable["id"], product.id)

Will this still work with the current version of rails?

Also, with products(:ram) how do I “extract” something like the price,
id or image_url out of it? In my book they just do it like this
@ram.image_url etc, but this now doesnt work. Whats the new way?

On 8/7/06, Petr [email protected] wrote:

Also, with “products(:ram)” how do I “extract” something like the price,
id or image_url out of it? In my book they just do it like this
@ram.image_url etc, but this now doesnt work. Whats the new way?

like so:

    product.price
    product.id
    product.image_url
    ...

or if you fancy, in your setup method, you could have:

@ram = products(:ram)

cheers,
jean-pierre

Being able to access the individual fixture records by instance
variable (e.g. @ram) was deprecated with Rails 1.0. If you really
want to turn it back on, set use_instantiated_fixtures to true in your
test_helper. Note, it is false by default for performance reasons.

Chris

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs