Alpha Curriculum - Hashes RSPEC mistake/typo

Hi! I believe there’s an issue with one of the test cases.

In the update_inventory tests it tests whether or not the old values get mutated
describe “update_inventory” do
let(:old) { { rubies: 10, diamonds: 5} }

it "mutates older" do
  new = { rubies: 20, diamonds: 5}
  update_inventory(old, new)
  expect(old).to eq(new)

From what I see and understand, the test case is comparing whether old and new are equal. Since update_inventory returns a new hash rather than modify the original old hash, the test should actually be expect(update_inventory(old,new)).to eq(new) and the previous like should be erased.

actual test case should look like this:

it "mutates older" do
  new = { rubies: 20, diamonds: 5}
  expect(update_inventory(old,new)).to eq(new)

I’m not App Academy staff or anything, but it looks intentional to me.

That’s what “mutates” means. So the fact that is says
it "mutates older" do
suggests the method is supposed to change old rather than returning a new hash.

The test case itself is incorrect. It says expect (old).to eq(new) which is never correct because old isn’t modified, the method isn’t supposed to modify old hash itself. New is an updated hash and old is called from the define step

The test case is fine.

old = { rubies: 10, diamonds: 5}
new = { rubies: 20, diamonds: 5}
old_after_update_inventory = { rubies: 20, diamonds: 5}

The two codes below are equivalent since update_inventory(old, new) modifies old.
Your method should modify old and also return the merged hash (which is actually old), which is redundant.

update_inventory(old, new) # `update_inventory` modifies `old`
expect(old).to eq(new)  # The modified `old` is then compared with `new`.

expect(update_inventory(old,new)).to eq(new) # `update_inventory` modifies and returns modified `old`.
                                            # The modified `old` is then compared with `new`.

How do you know that? It seems to me that the method is supposed to modify the old hash. That’s why the spec says it "mutates older".

I just double checked the requirements for the method. It didn’t seem clear to me originally but it does say update keys in the older inventory alongside with returning older hash. I was used to not updating the referenced arguments without the method with a !.

Thanks everyone for pointing this out. False alarm!