ruby on rails - Parameter passing and assert_difference -
i new both ruby , rails. don't understand why following code (which uses rails' [activesupport::testing.assert_difference]
1 method) doesn't require comma after parameter 1
. code comes chapter 7 of rails tutorial.
assert_difference 'user.count', 1 post_via_redirect users_path, ... end
the signature assert_difference
is:
assert_difference(expression, difference = 1, message = nil, &block)
thus expect comma required between difference
parameter , block
parameter not case.
why comma not required?
blocks aren't parameters - shows in method signature method captures block passed in proc, implementation detail leaked outside world. example if define method this
def foo(*args) end
then blocks passed method don't end in args
.
however if passing proc (or responds to_proc
), using &
argument prefix wish argument used method's block need comma.
my_proc = -> {post_via_redirect users_path} assert_difference user.count, 1, &my_proc
Comments
Post a Comment