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!

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.

Get your free chapter of Level Up Your Web Apps with Go

Get a free chapter of Level Up Your Web Apps with Go, plus updates and exclusive offers from SitePoint.

  • 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


Related books & courses
Rails Deep Dive

Available on SitePoint Premium. Check it out now!