Why the 'undefined method' assert_equal 'is thrown even after the request' test / unit '

I opened irb and entered:

require 'test/unit'

but when I used the method assert_equal, I got the following error: NoMethodError: undefined method 'assert_equal' for main:Object. Why does this happen even after the test / block requirement?

+5
source share
3 answers

assert_equaldefined in subclasses Test::Unit::TestCase, therefore only available in this class. You can succeed with the help of include Test::Unit::TestCaseloading these methods into the current area.

Most likely, you could write your tests in a short file and run them with ruby ./my_file.rb

+9
source

You can use ruby's built-in error testing

raise "Message you want to throw when error happens" if/unless "Condition when you want to throw the error "

OR

, "NoMethodError: undefined ` assert" main: Object", script:

require "test/unit/assertions"
include Test::Unit::Assertions
+6

Here's how statements are used:

class Gum
  def crisis; -42 end
end

# and as for testing:

require 'test/unit'

class GumTest < Test::Unit::TestCase
  def test_crisis
    g = Gum.new
    assert_equal -42, g.crisis
  end
end
+5
source

All Articles