如何使用Rspec模拟[]函数?

如何使用Rspec模拟[]函数?,rspec,Rspec,使用Rspec,我可以模拟Dir.glob(“/my/Dir/*.tmp”)这样做: expect(Dir).to receive(:glob).with("/my/dir/*.tmp") 如何模拟Dir[“/my/Dir/*.tmp”] expect(Dir).to receive(:"[]").with("/my/dir/*.tmp")

使用Rspec,我可以模拟
Dir.glob(“/my/Dir/*.tmp”)
这样做:

expect(Dir).to receive(:glob).with("/my/dir/*.tmp")
如何模拟
Dir[“/my/Dir/*.tmp”]

expect(Dir).to receive(:"[]").with("/my/dir/*.tmp")