Forum: Ruby Rspec for conditional code if-else

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
249c7fd851c5c5ac5a1abdb756472ae1?d=identicon&s=25 Arup Rakshit (my-ruby)
on 2014-05-08 14:47
(Received via mailing list)
Hi,

What will be the way to write a test code :

def meth(arg)
 arg == 2
end

if meth(val)
 call_meth1
else
 call_meth2
end

Regards,
Arup Rakshit
15000f55138ae94b0f362ed7c625461a?d=identicon&s=25 unknown (Guest)
on 2014-05-08 15:42
(Received via mailing list)
Am 08.05.2014 14:46, schrieb Arup Rakshit:
> end
That's not the right question to ask.

You should not write tests for "if-else" or for "Enumerable#any?" etc.
but instead decide what the desired behaviour of your method is for
a given set of preconditions, and test for that behaviour.

It might also be useful to look into the rspec files of some
open source projects as an example.

Regards,
Marcus
5b972395a92333843018b4add8af0437?d=identicon&s=25 Damián M. González (igorjorobus)
on 2014-05-08 20:00
Well, as the unkown guy says you should read RSpec book. But you should
think like this:

def meth(arg)
 arg == 2
end

meth(2).should be true
meth(5).should be false
This topic is locked and can not be replied to.