I have an instance method in String class who call the Array instance method “shuffle”. In order for me to test the method using RSpec, I want to stub it.
vowels = %w(a e i o u y)
vowels.shuffle
I tried:
Array.stub(:shuffle).and_return(%w(a e i o u y))
[].stub(:shuffle).and_return(%w(a e i o u y))
But none work 🙁 I am missing something here ? Mocking maybe ? But what should I mock then…
Thank you.
Use
any_instance. For example:Source