[rspec-rails] reload of objects in tests

hi,

I am kind of confused, why this code is behaving the way it does.
In a test, I wrote something like this:

it “should do something” do
@some = Factory(:some)
initial_object = @some

#do something with @some. e.g. update attributes etc.
@some.reload
@some.should_not == initial_object
end

Whenever I call reload on the object, the initial_object is set to
object again.
I don’t understand why a reload on @some is also updating
initial_object.
Can someone explain this to me please?

Hi,

On Fri, Apr 8, 2011 at 19:25, Clint [email protected]
wrote:

end

Whenever I call reload on the object, the initial_object is set to
object again.
I don’t understand why a reload on @some is also updating
initial_object.
Can someone explain this to me please?

It’s because @some and initial_object both point to the same instance
of an object. If you had:

initial_object = @some.clone

then initial_object and @some will point to separate instances.

HTH,
Mike