Stubbing ActiveRecord result arrays
- by Matthias
Using Ruby 1.8.6, stubbing a finder method to return an Array does not work when the code under test calls the 'count' method on the result:
User.any_instance.stubs(:friends).returns([user1, user2])
That's because Array.count has only been added in Ruby 1.8.7. Rails also adds a count method dynamically, I believe through the…