Programming Ruby 3.2 (5th Edition): B1.0 page 228, have_receieved + fake_user --> fake_product + Hash

@noelrappin

page 228, first paragraph, third line of code : have_receieved instead of have_received

 Failure/Error: expect(obj).to have_receieved(:cost)
   expected #<Double (anonymous)> to respond to `has_receieved?`

+++++ paragraph 5, second line of code : fake_user instead of fake_product

allow(fake_user).to receive(name: "pretzel")

 Failure/Error: allow(fake_user).to receive(name: "pretzel")
 
 NameError:
   undefined local variable or method `fake_user' for #<RSpec::ExampleGroups::Check "check class" (./kermit.rb:10)>

+++++ problem with the Hash :

 Failure/Error: allow(fake_product).to receive(name: "pretzel")
 
 NoMethodError:
   undefined method `to_sym' for {:name=>"pretzel"}:Hash
   Did you mean?  to_s
                  to_set

This works :

allow(fake_product).to receive(:name).with("pretzel")

class Muppet
    def name(parm)
    end
end

RSpec.describe 'check' do
    it 'have_received' do
        obj = double
        allow(obj).to receive(:cost).and_return("cheap")
        obj.cost
#       expect(obj).to have_receieved(:cost)
        expect(obj).to have_received(:cost)
    end
    
    it 'allow kermit' do
        kermit = Muppet.new
        allow(kermit).to receive(:greeting).and_return("Hi ho")
    end
    
    it 'check class' do
        fake_product = instance_double(Muppet)
#        allow(fake_product).to receive(name: "pretzel")
        allow(fake_product).to receive(:name).with("pretzel")
    end
end
% rspec -fd kermit.rb

check
  have_received
  allow kermit
  check class

Finished in 0.01081 seconds (files took 0.1463 seconds to load)
3 examples, 0 failures

The typos are both typos, but I think the code snippet is correct (I think yours is too, they are just doing different things), my line assumes that name takes no arguments, the stubbed line of code should act the same as allow(fake_product).to receive(name).and_return("pretzel"), which I should probably change it to, to be consistent with the previous examples.