Exemple de code Ruby

require 'tp1a'
require 'tp1b'
require 'tp1c'
require 'tp2a'
require 'tp2b'
 
require 'test/unit'
require 'yaml'
require 'pp'
require 'stringio'      # to cat file content to stdin stream
 
@@defin       = $stdin
@@tp1_result  = YAML.load_file('tp1.yaml')
@@tp1         = TP1.new
 
 
class TP1_tests < Test::Unit::TestCase
    def test_a()
        $stdin = StringIO.new(File.open('tp1.txt','rb').read)
        assert(
            @@tp1_result == @@tp1.read_from_stdin
        )
    end
    def test_b()
        $stdin = StringIO.new('tp1b_input.txt')
        @@tp1.get_input_file_name_from_stdin
        $stdin = StringIO.new('tp1b_output.txt')
        @@tp1.get_output_file_name_from_stdin
        assert(
            @@tp1_result == @@tp1.read_from_file_and_write_to_file
        )
    end
    def test_c()
        ARGV.clear
        ARGV.push '--output-file'
        ARGV.push 'tp1c_output.txt'
        @@tp1.parse_command_line
        $stdin = StringIO.new(File.open('tp1.txt','rb').read)
        assert(
            @@tp1_result == @@tp1.read_from_stdin_and_write_to_file
        )
    end
end