Suppose a User has many Items, and I want to spec that when a user is
destroyed its associated items are destroyed.  I'm seeing some unexpected
behavior:

describe User do
  before(:each) do
    @user = create_user   # helper method that actually creates & saves a
user
    @item = create_item
    @user.items << @item
  end

  # THIS WORKS
  it "should delete associated items when a user is destroyed" do
    @item.should == @user.items[0]
    @user.items[0].should_receive(:destroy)
    @user.destroy
  end

  # THIS FAILS
   it "should delete associated items when a user is destroyed" do
    @item.should_receive(:destroy)
    @user.destroy
  end
end

Why does the message expectation fail on @item but succeed on
@user.items[0], even though @user.items[0] == @item ?

Thanks...
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to