Sign inSign up

patriciomoreno/codeworkout-ruby

By patriciomoreno

•Updated over 8 years ago

Image to test Ruby code

Image
0

59

patriciomoreno/codeworkout-ruby repository overview

⁠This image contains:
  • Ruby 2.5
⁠Example
docker run --rm -v $(pwd):$(pwd) -w $(pwd) patriciomoreno/codeworkout-ruby:v1.0 ruby tc_simple_number.rb
⁠Content of simple_number.rb
class SimpleNumber
  def initialize(num)
    raise unless num.is_a?(Numeric)
    @x = num
  end
  def add(y)
    @x + y
  end
  def multiply(y)
    @x * y
  end
end
⁠Content of tc_simple_number.rb
require_relative "simple_number"
require "test/unit"
class TestSimpleNumber < Test::Unit::TestCase
  def test_simple
    assert_equal(4, SimpleNumber.new(2).add(2) )
    assert_equal(4, SimpleNumber.new(2).multiply(2) )
  end

  def test_typecheck
    assert_raise( RuntimeError ) { SimpleNumber.new('a') }
  end

  def test_failure
    assert_equal(3, SimpleNumber.new(2).add(2), "Adding doesn't work" )
  end
end

Tag summary

Content type

Image

Digest

Size

329.2 MB

Last updated

over 8 years ago

docker pull patriciomoreno/codeworkout-ruby:v1.0