Frederick Cheung
2008-Nov-27 11:38 UTC
Making assert_difference''s default message more helpful
I like assert_difference, but I find the error messages slightly unhelpful when I''m verifying more than one thing. Suppose something should create both a new customer and a question, I could write assert_difference ''Question.count'' do assert_difference ''Customer.count'' do ... end end Unlike a normal assertion the test line causing the failure will be a few lines down the stack trace so it''s not obvious to me with a quick glance which of the assertions have failed (although this is fixable by providing a custom failure message). I''d rather write assert_difference [''Question.count'', ''Customer.count''] do ... end but if a failure occurs here then I genuinely don''t know which assertion has failed (unless I can remember that ''expected 4 got 3'' must be talking about the customer assertion because I remember the number of records defined in the fixtures). It seems to me that this could be made more helpful if the default error message included the expression being evaluated eg something along the lines of Customer.count: expected 4, got 3 Thoughts? Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Damian Janowski
2008-Nov-27 11:46 UTC
Re: Making assert_difference''s default message more helpful
On Thu, Nov 27, 2008 at 8:38 AM, Frederick Cheung <frederick.cheung@gmail.com> wrote:> but if a failure occurs here then I genuinely don''t know which > assertion has failed (unless I can remember that ''expected 4 got 3'' > must be talking about the customer assertion because I remember the > number of records defined in the fixtures). > > It seems to me that this could be made more helpful if the default > error message included the expression being evaluated eg something > along the lines of > > Customer.count: expected 4, got 3+1! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Mislav Marohnić
2008-Nov-27 12:01 UTC
Re: Making assert_difference''s default message more helpful
On Thu, Nov 27, 2008 at 12:38, Frederick Cheung <frederick.cheung@gmail.com>wrote:> > I like assert_difference, but I find the error messages slightly > unhelpful when I''m verifying more than one thing.What about github.com/rails/rails/commit/00e2ba ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Nov-27 12:12 UTC
Re: Making assert_difference''s default message more helpful
On Nov 27, 12:01 pm, "Mislav Marohnić" <mislav.maroh...@gmail.com> wrote:> On Thu, Nov 27, 2008 at 12:38, Frederick Cheung > <frederick.che...@gmail.com>wrote: > > > > > I like assert_difference, but I find the error messages slightly > > unhelpful when I''m verifying more than one thing. > > What about github.com/rails/rails/commit/00e2ba ?D''oh - haven''t moved stuff to 2.2 yet and hadn''t notice that commit. Sorry for the noise! Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---