[rspec-users] [RSpec] Cloning objects and leaking state

Nick Hoffman nick at deadorange.com
Wed Jan 28 12:49:39 EST 2009

On 28/01/2009, at 12:16 PM, Pat Maddox wrote:
>> If it doesn't automatically clone (it may, I don't know), it probably
>> should provide a lambda syntax so you can do:
>> default :subtitles => lambda { [] }
> Yeah, I just looked at the code for ARD and this is the problem.  You
> can pass in immutable objects and they don't get affected for obvious
> reasons.  But with a mutable object like an array, you need to pass it
> a lambda so that it's creating a new instance each time.
> Pat

That makes a lot of sense.

The active_record_defaults README[1] shows strings being used for  
default values. The problem that I experienced in this thread will  
plague the README's example if a non-assignment operation is performed  
on the attribute.

[1] http://svn.viney.net.nz/things/rails/plugins/active_record_defaults/README

Thanks again, Pat, David, and Zach!

More information about the rspec-users mailing list