Neeraj Kumar
2006-Jun-24 23:56 UTC
[Rails] @version_control_book not available while testing - AWD book 1 page 148
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060624/387ef61c/attachment.html
Mike Harris
2006-Jun-25 00:57 UTC
[Rails] Re: @version_control_book not available while testing - AWD
Neeraj Kumar 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? > > Thankshttp://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 -- Posted via http://www.ruby-forum.com/.