Cloud_cal
Cloud_cal

Reputation: 142

How to stub a method that is also the name of a hash in ruby?

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.

Upvotes: 1

Views: 199

Answers (0)

Related Questions