David Stevenson
2008-Sep-25 03:14 UTC
How do you write tests in rails that check implementation?
Koz et al, I''m trying to write a patch for this ticket: http://rails.lighthouseapp.com/projects/8994/tickets/1104-references_eager_loaded_tables-should-search-tables-in-join-clauses I want to make rails better at guessing which style of :include to execute (pre-2.1 vs 2.1+), but I don''t see any tests like what I''m trying to test in eager_test.rb So how would I test that rails is doing the :include one way vs another? Both would work and produce identical results at the end, so it seems not possible to functionally test this. Yet all these tests check the function of finders, rather than unit testing the individual support methods (I could obviously test this by unit testing references_eager_loaded_tables? method). Normally here, I''d use expectations to see that things are working under the hood the right way... Thanks guys! -David Stevenson Pivotal Labs --~--~---------~--~----~------------~-------~--~----~ 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-Sep-25 12:40 UTC
Re: How do you write tests in rails that check implementation?
On 25 Sep 2008, at 04:14, David Stevenson wrote:> > Koz et al, > > I''m trying to write a patch for this ticket: > > http://rails.lighthouseapp.com/projects/8994/tickets/1104-references_eager_loaded_tables-should-search-tables-in-join-clauses > > I want to make rails better at guessing which style of :include to > execute (pre-2.1 vs 2.1+), but I don''t see any tests like what I''m > trying to test in eager_test.rb > > So how would I test that rails is doing the :include one way vs > another? Both would work and produce identical results at the end, so > it seems not possible to functionally test this. Yet all these tests > check the function of finders, rather than unit testing the individual > support methods (I could obviously test this by unit testing > references_eager_loaded_tables? method). Normally here, I''d use > expectations to see that things are working under the hood the right > way... >Neat - I''ve been hitting that recently. Bit of a kludge but could you just look at the number of queries made (ie 1 for join based monster, number of associations + 1 in other cases) ? 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 -~----------~----~----~----~------~----~------~--~---
I haven''t look at the implementation of this, so I can only answer generally. However, at some point in there the code must call different methods based on which finder strategy it chooses. You could identify the point at which the code paths diverge and mock the unique methods calls for each path. Perhaps this is what you mean by using expectations? Of course, I suspect you (David) are familiar with my particular opinion on digging around in implementation details with unit tests. If you could extract the code responsible for choosing the finder strategy in such a way that you could use or test it in isolation, then that would be the ideal. On Sep 24, 8:14 pm, David Stevenson <dsboul...@gmail.com> wrote:> Koz et al, > > I''m trying to write a patch for this ticket: > > http://rails.lighthouseapp.com/projects/8994/tickets/1104-references_... > > I want to make rails better at guessing which style of :include to > execute (pre-2.1 vs 2.1+), but I don''t see any tests like what I''m > trying to test in eager_test.rb > > So how would I test that rails is doing the :include one way vs > another? Both would work and produce identical results at the end, so > it seems not possible to functionally test this. Yet all these tests > check the function of finders, rather than unit testing the individual > support methods (I could obviously test this by unit testing > references_eager_loaded_tables? method). Normally here, I''d use > expectations to see that things are working under the hood the right > way... > > Thanks guys! > > -David Stevenson > Pivotal Labs--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---