I just saw Marcel''s change to assert_difference that changes the method API to take a string param that is evaled in a lambda. http://dev.rubyonrails.org/changeset/6693 I much preferred the old API, since it''s simple enough to pass a lambda. Passing a string means the lambda is in the wrong scope and doesn''t have access to objects in the test case scope. For an example of how I was using the old API: http://blog.hasmanythrough.com/2007/5/2/getting-arbitrary-with- assert_difference -- Josh Susser http://blog.hasmanythrough.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mon, May 07, 2007 at 11:05:25PM -0700, Josh Susser wrote:> I just saw Marcel''s change to assert_difference that changes the > method API to take a string param that is evaled in a lambda. > > http://dev.rubyonrails.org/changeset/6693 > > I much preferred the old API, since it''s simple enough to pass a > lambda. Passing a string means the lambda is in the wrong scope and > doesn''t have access to objects in the test case scope.Wouldn''t lambda { eval(expression, block.binding) } take care of that? marcel -- Marcel Molina Jr. <marcel@vernix.org> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> http://blog.hasmanythrough.com/2007/5/2/getting-arbitrary-with- > assert_differenceThat''s pretty nice, but a lambda and :call is a bit nasty, and I like the string for simple cases (all the ({}) stuff is a bit like line noise). I''d take a patch which can accept a string, or a lambda though. -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mon, May 07, 2007 at 11:05:25PM -0700, Josh Susser wrote:> I just saw Marcel''s change to assert_difference that changes the > method API to take a string param that is evaled in a lambda. > > http://dev.rubyonrails.org/changeset/6693 > > I much preferred the old API, since it''s simple enough to pass a > lambda. Passing a string means the lambda is in the wrong scope and > doesn''t have access to objects in the test case scope.Any issues with this? % svn diff Index: test/test_test.rb ==================================================================--- test/test_test.rb (revision 6693) +++ test/test_test.rb (working copy) @@ -46,4 +46,11 @@ @object.decrement end end + + def test_expression_is_evaluated_in_the_appropriate_scope + local_scope = ''foo'' + assert_difference ''local_scope; @object.num'' do + @object.increment + end + end end Index: lib/active_support/core_ext/test/difference.rb ==================================================================--- lib/active_support/core_ext/test/difference.rb (revision 6694) +++ lib/active_support/core_ext/test/difference.rb (working copy) @@ -20,7 +20,7 @@ # post :delete, :id => ... # end def assert_difference(expression, difference = 1, &block) - expression_evaluation = lambda { eval(expression) } + expression_evaluation = lambda { eval(expression, block.binding) } original_value = expression_evaluation.call yield assert_equal original_value + difference, expression_evaluation.call % ruby test/test_test.rb Loaded suite test/test_test Started ...... Finished in 0.00133 seconds. 6 tests, 6 assertions, 0 failures, 0 errors marcel -- Marcel Molina Jr. <marcel@vernix.org> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---