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. <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---