Forum: Ruby Rspec for conditional code if-else

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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.