O'Reilly logo

Ruby by Example by Kevin C. Baird

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

#29 Testing temperature_converter.rb (tests/test_temp_converter.rb)

Up until this point, our testing scripts have been relatively primitive, and to a very large degree, we have rolled our own testing solutions. It’s silly to do that repeatedly, especially in computer programs, because good programming languages allow you to express abstract concepts abstractly, as well as to adapt general-purpose tools in code libraries to your specific needs.

Ruby has a general-purpose testing library called Test::Unit. Here is code that allows you to use its power to test the script temperature_converter.rb.

The Code

  #!/usr/bin/env ruby
  # test_temp_converter.rb

❶ require 'temperature_converter'
  require 'test/unit'

❷ class Tester < Test::Unit::TestCase    Unit Testing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required