#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 ...

Get Ruby by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.