By Darren Jones

Simple Testing in Ruby Using Minitest

By Darren Jones

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!

  • 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


Get the latest in Ruby, once a week, for free.