[yast-devel] Reminder: verify_partial_doubles is not default
Hi, again I hit by thinking that verify_partial_doubles is now default in rspec3. It is not and will be in rspec4. So what it means? rspec does not check if mocked methods exists at all and it can result in many not so funny errors in test suite. I am just faced it in network, so I create non trivial commit[1] that enables it there. It includes also how to avoid failures on mocked class[2] which avoided build dependencies. From list of errors it can check is typos[3], mocking of wrong class[4] and mocking non-existing methods[5]. So feel free to take it as inspiration and enable it also in your test helper. Josef [1] https://github.com/yast/yast-network/pull/830/commits/e18da64fce25242a517109... [2] https://github.com/yast/yast-network/pull/830/commits/e18da64fce25242a517109... [3] https://github.com/yast/yast-network/pull/830/commits/e18da64fce25242a517109... [4] https://github.com/yast/yast-network/pull/830/commits/e18da64fce25242a517109... [5] https://github.com/yast/yast-network/pull/830/commits/e18da64fce25242a517109... -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Thu, Jun 13, 2019 at 04:21:13PM +0200, Josef Reidinger wrote:
again I hit by thinking that verify_partial_doubles is now default in rspec3. It is not and will be in rspec4. So what it means? rspec does not check if mocked methods exists at all and it can result in many not so funny errors in test suite. I am just faced it in network, so I create non trivial commit[1] that enables it there. It includes also how to avoid failures on mocked class[2] which avoided build dependencies. From list of errors it can check is typos[3], mocking of wrong class[4] and mocking non-existing methods[5].
Thanks for the tip!
[2] https://github.com/yast/yast-network/pull/830/commits/e18da64fce25242a517109...
I have tested it and it does not work ;-) I have a fix: https://github.com/yast/yast-network/pull/841 -- Martin Vidner, YaST Team http://en.opensuse.org/User:Mvidner
Dne 13. 06. 19 v 16:21 Josef Reidinger napsal(a):
Hi, again I hit by thinking that verify_partial_doubles is now default in rspec3. It is not and will be in rspec4. [...]
So feel free to take it as inspiration and enable it also in your test helper.
Accidentally I found another problem, this time in the kdump module. If you need to mock the AutoYaST mode in the tests you would do: allow(Yast::Mode).to receive(:autoinstallation).and_return(true) This looks right, doesn't it? Um.... unfortunately it's wrong. The method is surprisingly called "Yast::Mode.autoinst". Accidentally the test passed anyway so this went undetected. After enabling verifying doubles RSpec complained that the method does not exist. In this case it was harmless, but it can be much worse. If you do the same typo in the test and in the code then it might crash in runtime because of calling an undefined method. Currently I'm moving the YaST packages from Travis to GitHub Actions and I'm usually touching the test_helper.rb files so I'm enabling this RSpec feature as well. -- Ladislav Slezák YaST Developer SUSE LINUX, s.r.o. Corso IIa Křižíkova 148/34 18600 Praha 8
El miércoles, 2 de diciembre de 2020 10:00:06 (WET) Ladislav Slezak escribió:
Accidentally I found another problem, this time in the kdump module.
If you need to mock the AutoYaST mode in the tests you would do:
allow(Yast::Mode).to receive(:autoinstallation).and_return(true)
This looks right, doesn't it? Um.... unfortunately it's wrong. The method is surprisingly called "Yast::Mode.autoinst".
Yes, I agree, the name is surprising (well, I am used to it, but...). JFYI, there is a Yast::Mode.auto which covers autoinstallation and autoupgrade. Regards, Imo -- Imobach González Sosa YaST Team at SUSE LLC https://imobachgs.github.io/
participants (4)
-
Imobach González Sosa
-
Josef Reidinger
-
Ladislav Slezak
-
Martin Vidner