Rspec: expect "super" to get called
Asked Answered
T

0

7

I have a very short function to test:

def my_fn
  if some_condition
    super(@my_attr)
  end
end

And I want my spec to do verify that super gets called, but I can't do the following because :super appears not to be a message that ever gets sent:

    expect(subject).to receive(:super)
Tynishatynwald answered 11/10, 2019 at 18:58 Comment(6)
Super is not a message - its a keyword.Typhoid
@Typhoid : it makes sense why it doesn't work, then. Do you have any idea how I can achieve my intent?Tynishatynwald
#15856834Typhoid
But I would pay attention to the answer by Myron Marston - he is (was?) a core developer for RSpec.Typhoid
As a general - don't mock object under test. Mock only objects that it's using, but mocking the same object as you're testing is asking for trouble.Selfsacrifice
You shouldn't test implementation, you should test behaviour. When you have a call to super, the test should pass even if you replace "super" with the code from your original method. So, test that the call does "what" it should and not "how" it does that.Mcintosh

© 2022 - 2024 — McMap. All rights reserved.