samedi 22 août 2015

Ruby: undefined method `assert'

I follow this code on codeschool

string_extension_test.rb

gem "minitest", "~> 4.0"
require "test/unit"
require "string_extension"

assert "3".is_number?
assert !"Blash".is_number?

string_extension.rb

class String 
    def is_number?
        if self =~/^\d+$/
            true
        else
            false
        end
    end
end

And I type ruby -I. string_extension_test.rb

However, it shows that

string_extension_test.rb:6:in `<main>': undefined method `assert' for main:Object (NoMethodError)

I have tried add include Test::Unit::Assertions in string_extension_test.rb, it can pass, but no test case.

the output will be

Finished tests in 0.013038s, 0.0000 tests/s, 0.0000 assertions/s.
0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

Aucun commentaire:

Enregistrer un commentaire