Writing tests for your app is kind of like ensuring that your car brakes will still work, even if you accidentally change the language of your sat-nav to German. Really, it’s about avoiding nasty surprises. Today, I’m going to show you how to write tests in Ruby using MiniTest. Enjoy!

Tags: learnable, minitest, Testing
DAZ is the author of Jump Start Sinatra, a short book that helps you to get up to speed with Sinatra over a weekend. He's been using Sinatra since 2009. DAZ lives in Manchester, UK where he teaches maths and plays water polo.

  • heel

    number.respond_to?(:each) would be better to write this way:


    • daz4126

      This wouldn’t allow you to enter an array of numbers though …

      • heel

        yes, but you didn’t do that in your example. Even if that would be the case, I rather go for something like [Array, Range].include?(number.class)

        • daz4126

          Hi Heel,

          Yes both of those would work, but I think I’d still rather test that an object responded to a method rather such as each rather than testing for specific types of object i.e. duck typing

          • jonnysnip3r


Special Offer
Free course!

Git into it! Bonus course Introduction to Git is yours when you take up a free 14 day SitePoint Premium trial.