Unexpected TypeError in Ruby 3.1 When Using Keyword Arguments with RSpec Mocks
I'm confused about I'm working on a personal project and This might be a silly question, but I'm working with a `TypeError` when using RSpec mocks with keyword arguments in my Ruby 3.1 application. Specifically, I have a method that accepts keyword arguments, and when I try to stub it using RSpec, it raises an behavior. Here's the method I want to test: ```ruby class UserService def initialize(user_repository) @user_repository = user_repository end def create_user(name:, email:) @user_repository.save(name: name, email: email) end end ``` And here is how I'm attempting to write the test: ```ruby RSpec.describe UserService do let(:user_repository) { double('UserRepository') } let(:service) { UserService.new(user_repository) } it 'creates a user' do expect(user_repository).to receive(:save).with(name: 'John Doe', email: 'john@example.com').and_return(true) service.create_user(name: 'John Doe', email: 'john@example.com') end end ``` When I run this test, I get the following behavior: ``` TypeError: wrong argument type String (expected Hash) ``` I've checked the method signature and the way I'm calling the method in the test, and everything seems correct. I also tried explicitly passing the keyword arguments as a hash by doing this: ```ruby service.create_user({name: 'John Doe', email: 'john@example.com'}) ``` However, this still throws the same `TypeError`. I suspect there might be something related to how RSpec is handling keyword arguments in Ruby 3.1. Has anyone else experienced this scenario, or can anyone provide insight into how to properly mock methods with keyword arguments in RSpec? Any help would be greatly appreciated! How would you solve this? Is there a better approach? I'm working on a application that needs to handle this. Am I missing something obvious?