Wrote a simple program decided, check out MiniTest this program.

require 'minitest/autorun' class Test1 attr_accessor :x def z "Hello #{@x}" end end class Test2<MiniTest::Test def test_h @xx=Test1.new @xx.x="World" puts assert_equal "Hello World",@xx.z end end 

MiniTest does not generate errors, but when I added the puts statement, here is an example of code, it gives me an error.

  require 'minitest/autorun' class Test1 attr_accessor :x def z puts "Hello #{@x}" end end class Test2<MiniTest::Test def test_h @xx=Test1.new @xx.x="World" puts assert_equal "Hello World",@xx.z end end 

What to do in the code so that MiniTest perceives puts ok?

  • 2
    puts not an operator, but a method. Get into the habit of normally indenting so that you can visually select the body of a class and its individual methods. And what kind of error does it add if you add puts ? - D-side

1 answer 1

I did not find a direct solution and found a workaround. I use built-in gem logger

https://ruby-doc.org/stdlib-2.1.0/libdoc/logger/rdoc/Logger.html

usage example

@logger = Logger.new(STDERR)

and then

@logger.info('anything you want')