In the page 148 of the AWD book it’s mentioned that the while testing
@products and @version_control_book are automatically made available.
That’s not the case with me. In my test environment I don’t get those
two
variables.
I was wondering if anything has changed in Rails 1.1 because in the new
edition of the book (AWD - edition 2) there is no mention of such
feature in
testing chapter?
Thanks
Neeraj K. wrote:
In the page 148 of the AWD book it’s mentioned that the while testing
@products and @version_control_book are automatically made available.
That’s not the case with me. In my test environment I don’t get those
two
variables.
I was wondering if anything has changed in Rails 1.1 because in the new
edition of the book (AWD - edition 2) there is no mention of such
feature in
testing chapter?
Thanks
http://clarkware.com/cgi/blosxom/2005/10/24
On-Demand Instantiated Fixtures
By default in Rails 1.0, fixtures aren’t instantiated and assigned to
instance variables until you need them. Whereas previous releases would
automatically create a @version_control_book instance variable, for
example, before each test method, you can now use the fixture accessor
method products(:version_control_book) to load fixture data into
variables on demand.
So before running the test with instantiated fixtures disabled, we need
to change the tests to use fixture accessor methods:
def test_add_one_product
@cart.add_product products(:version_control_book)
assert_equal 1, @cart.items.size
end
def test_add_duplicate_products
@cart.add_product products(:version_control_book)
@cart.add_product products(:version_control_book)
@cart.add_product products(:automation_book)
assert_equal 2, @cart.items.size
end