1

I am new to ruby mocha and need to mock a method which is also a hash. Currently the method does two things:

Products.elements.oldest # returns the oldest element
Products.elements['second'] # returns the second element

and what i did was

Products.stubs(:elements).returns(mock, {'second' => mock})
Products.elements.stubs(:oldest).returns mock

I am not sure if this is the right way to do that, but it passes the compiler.

Vega
  • 27,856
  • 27
  • 95
  • 103
Cloud_cal
  • 132
  • 2
  • 12
  • "Passes the compiler" means the syntax is valid and nothing more. Don't trust that to mean anything significant. The sentence "Frogs dance do ham hurricane" has no spelling mistakes but still makes no sense. Does your code work as you'd expect? That's the real test. – tadman Jul 17 '15 at 17:35
  • @tadman No, it doesn't. I was thinking if there is a way to mock the elements so you will get different return values if you call that method in different ways, like elements.oldest and elements['second']. – Cloud_cal Jul 17 '15 at 18:10

0 Answers0