Home > Back-end >  Where's the official doc for RSpec's instance_double method that outline how you can confi
Where's the official doc for RSpec's instance_double method that outline how you can confi

Time:12-15

For below code in spec:

let(:my_model) { instance_double(MyModel, is_happy: true) }

I want to confirm what is_happy: true does exactly.

I think it stub the is_happy instance method of MyModel double and make it always return true in the spec, but I want to see official RSpec doc confirming this.

I can see this RSpec doc, but it doesn't mention the method stubbing part.

Where in the doc is this documented and how should I navigate docs around RSpec?

CodePudding user response:

From the Yard documentation:

instance_double(doubled_class, stubs)

Parameters:

  • doubled_class (String, Class)
  • stubs (Hash) — hash of message/return-value pairs

is_happy: true will make the double return true when sent the the message is_happy.

RSpec has both the normal API documentation which is generated by Yard from the code and the guide style documenation that you have linked. Its quite common to have both in a well documented project since they serve different purposes.

  • Related