Testing your Ruby code: IRB vs. Pry

In this post I’m going to look into the two tools that I have used most so far in my albeit short programming career.IRBThe first tool introduced to me was IRB, or Interactive Ruby Shell..IRB is a ruby shell or REPL (Read — Execute — Print — Loop) that works essentially as your Ruby testing playground..You can start IRB by simply entering irb in your terminal..You can then start running your ruby code and test away..It looks a little something like this:[11:37:41] ~// ♥ irb2.3.3 :001 > class Mariel2.3.3 :002?> def drinks_coffee2.3.3 :003?> return "Mariel drinks a cup of coffee..☕️"2.3.3 :004?> end2.3.3 :005?> end=> :drinks_coffee2.3.3 :006 > Mariel.new.drinks_coffee=> "Mariel drinks a cup of coffee..☕️"“Neat, but why should I care?.I’m already a coding god and don’t need to test.”IRB allows you to quickly run a script in your terminal window and test the return values, among other things..Ruby is a language categorized by “dynamic typing” in that your methods do not have to explicitly state what your return will be..When your code breaks or isn’t working the way you want, you should absolutely be testing your assumptions to figure out what went wrong..If I had a dollar for everytime I had a silly typo that broke my entire script…I’d have a lot of dollars..The mantra at Flatiron School is “test early and often”.. More details

Leave a Reply