Simple Testing in Ruby Using Minitest

Tweet

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 JavaScript: Novice to Ninja Sample

Get a free 32-page chapter of JavaScript: Novice to Ninja and receive updates on exclusive offers from SitePoint.

  • 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

          • jonnysnip3r

            Schooled