I’m trying to do this:
def assert_record_not_found(method, object, action, params)
begin
method action, params
object.find_by_id(p.id).should_not be_nil
rescue ActiveRecord::RecordNotFound
assert true
end
end
but when I do the call:
assert_record_not_found(delete, MyObject, :destroy, {:id => o.id})
I get an error that delete has no arguments… which makes sense, given that delete is a rails testing function.
So, is there a way to pass a pointer to the method as an argument instead of passing the method itself?
The easiest way is to use ruby blocks:
And then call your method:
You can also get the method object and pass it to your function:
Using blocks is far more ruby-ish.