Complete the code to create a mock object in Ruby.
mock_user = double([1])In Ruby, double(:user) creates a mock object named :user.
Complete the code to stub the method 'name' to return 'Alice'.
allow(mock_user).to receive(:name).and_return([1])Use a string "Alice" to return the name properly.
Fix the error in the code to expect the method 'greet' to be called once.
expect(mock_user).to [1](:greet).oncereceive keyword.The correct syntax is expect(mock_user).to receive(:greet).once.
Fill both blanks to stub a method 'age' that returns 30 only if called with argument 'true'.
allow(mock_user).to receive(:age).with([1]).and_return([2])
false instead of true.The method age is stubbed to return 30 when called with true.
Fill all three blanks to create a mock, stub 'status' to 'active', and expect 'update' to be called once.
mock_account = double([1]) allow(mock_account).to receive(:status).and_return([2]) expect(mock_account).to receive([3]).once
This code creates a mock named :account, stubs status to return "active", and expects update to be called once.
