Simple Testing in Ruby Using Minitest

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!

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

  • heel

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

    number.is_a?(Range)

    • 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