I''m working through the testing chapter in the Beta Book & I''ve ran into a problem that has me stumped. In the test_update method, I''m getting the following error: bash-2.05b$ ruby test/unit/product_test.rb Loaded suite test/unit/product_test Started ..F Finished in 0.05009 seconds. 1) Failure: test_update(ProductTest) [test/unit/product_test.rb:28]: <false> is not true. 3 tests, 10 assertions, 1 failures, 0 errors Here''s the code. Line 28 is assert @product.save. def test_update assert_equal 29.95, @product.price @product.price = 99.99 assert @product.save @product.reload assert_equal 99.99, @product.price end Any ideas? _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Mon, 2005-06-13 at 22:42 -0700, Mike Payson wrote:> I''m working through the testing chapter in the Beta Book & I''ve ran > into a problem that has me stumped.+1 on the same piece of code.> > Here''s the code. Line 28 is assert @product.save. > > def test_update > assert_equal 29.95, @product.price > @product.price = 99.99 > assert @product.save > @product.reload > assert_equal 99.99, @product.price > end > > Any ideas?I don''t know much about testing (that''s why I''m reading the chapter/book), but I changed: assert @product.save to assert @product.update strictly on a lark, and the test passed. I don''t know if this is a typo in the book, or if my solution is a real solution, so I too would be interested to hear from others on this. HTH, Howard
Lord Khaos said the following on 2005-06-14 02:12:> On Mon, 2005-06-13 at 22:42 -0700, Mike Payson wrote: > >>Here''s the code. Line 28 is assert @product.save. >> >> def test_update >> assert_equal 29.95, @product.price >> @product.price = 99.99 >> assert @product.save >> @product.reload >> assert_equal 99.99, @product.price >> end >> >>Any ideas? > > I don''t know much about testing (that''s why I''m reading the > chapter/book), but I changed: > > assert @product.save > to > assert @product.updateWhat I do in my tests is this: assert @product.save, "Validation errors: #{@product.errors.full_messages}" Which gives me the validation errors on save failure. Alternatively, do @product.save! (notice the exclamation mark), which will raise an exception if something can''t be saved. Bye ! François
On Jun 14, 2005, at 7:30 AM, François Beausoleil wrote:> Lord Khaos said the following on 2005-06-14 02:12: > >> On Mon, 2005-06-13 at 22:42 -0700, Mike Payson wrote: >> >>> Here''s the code. Line 28 is assert @product.save. >>> >>> def test_update >>> assert_equal 29.95, @product.price >>> @product.price = 99.99 >>> assert @product.save >>> @product.reload >>> assert_equal 99.99, @product.price >>> end >>> >>> Any ideas? > > What I do in my tests is this: > > assert @product.save, > "Validation errors: #{@product.errors.full_messages}" > > Which gives me the validation errors on save failure. > Alternatively, do @product.save! (notice the exclamation mark), > which will raise an exception if something can''t be saved.As the author of that chapter, I''d be very interested to hear about the validation errors you see using the trick above, Mike. Several kind reviewers successfully ran through the code before the beta book was released, so I''m stumped as to why it doesn''t work for you. Thanks! Mike
On 6/14/05, Mike Clark <mike-BLA3tSOjuzdl57MIdRCFDg@public.gmane.org> wrote:> > On Jun 14, 2005, at 7:30 AM, François Beausoleil wrote: > > > Lord Khaos said the following on 2005-06-14 02:12: > > > >> On Mon, 2005-06-13 at 22:42 -0700, Mike Payson wrote: > >> > >>> Here''s the code. Line 28 is assert @product.save. > >>> > >>> def test_update > >>> assert_equal 29.95, @product.price > >>> @product.price = 99.99 > >>> assert @product.save > >>> @product.reload > >>> assert_equal 99.99, @product.price > >>> end > >>> > >>> Any ideas? > > > > What I do in my tests is this: > > > > assert @product.save, > > "Validation errors: #{@product.errors.full_messages}" > > > > Which gives me the validation errors on save failure. > > Alternatively, do @product.save! (notice the exclamation mark), > > which will raise an exception if something can''t be saved. > > As the author of that chapter, I''d be very interested to hear about > the validation errors you see using the trick above, Mike. > > Several kind reviewers successfully ran through the code before the > beta book was released, so I''m stumped as to why it doesn''t work for > you. > >It was a validation issue. Adding "Validation errors: #{@product.errors.full_messages}" told me that the problem was in my image_url (no .jpg). It might be worth adding that to the code in the book. I suspect that I won''t be the only person to lazy to type the entire image_url, so I suspect that others will be bitten here as well. Without that, the default error message, ''<false> is not true'', is a bit less then informative. Otherwise, it''s been a great chapter in a great book. Thanks (and thanks to Francois for pointing out how to get the validation errors)! Mike
On Tue, 2005-06-14 at 17:15 -0700, Mike Payson wrote:> On 6/14/05, Mike Clark <mike-BLA3tSOjuzdl57MIdRCFDg@public.gmane.org> wrote: > > > > As the author of that chapter, I''d be very interested to hear about > > the validation errors you see using the trick above, Mike.> Adding "Validation errors: > #{@product.errors.full_messages}" told me that the problem was in my > image_url (no .jpg).Exact same result here, except I left off the protocol (http://)-- not so much out of laziness, but from not understanding the particulars about how to write the image path in the db so that I can retrieve it via code from /public/images without using an absolute path. Still a bit unclear on that point, but can hardly blame Mike Payson for the test failing if I''m not going to follow the book''s example to the letter, now can I? Thanks for following up on this, and also to François for the code snippet to identify the issue. Howard
On Wed, 2005-06-15 at 00:18 -0400, Lord Khaos wrote:> but can hardly blame Mike Payson for the test > failing if I''m not going to follow the book''s example to the letter, now > can I?Sorry, I meant Mike Clark, obviously :) Howard
On Jun 14, 2005, at 7:30 AM, François Beausoleil wrote:> What I do in my tests is this: > > assert @product.save, > "Validation errors: #{@product.errors.full_messages}" > > Which gives me the validation errors on save failure.Thanks for everyone''s responses on this. We''ll update the test in the testing chapter to use this technique. Mike http://clarkware.com
I usually put a to_yaml on the end of any potentially large / deep output like this so it''s nicely formatted. Chris On 6/17/05, Mike Clark <mike-BLA3tSOjuzdl57MIdRCFDg@public.gmane.org> wrote:> > On Jun 14, 2005, at 7:30 AM, François Beausoleil wrote: > > > What I do in my tests is this: > > > > assert @product.save, > > "Validation errors: #{@product.errors.full_messages}" > > > > Which gives me the validation errors on save failure. > > Thanks for everyone''s responses on this. > > We''ll update the test in the testing chapter to use this technique. > > Mike > http://clarkware.com > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >