Syntax assert_output Ruby minitest

I am new to minitest and still new to ruby ​​and am very tired of trying to resolve this issue to no avail. I would be very grateful for the help:

What is the exact syntax of assert_output in minitest ruby?

Everything I find on github or elsewhere seems to use parentheses. However, I get an error when I do not use a block with assert_output, which makes sense because the definition of this method contains a yield statement.

But I can't get it to work, no matter what I try.

testclass.rb

class TestClass def output puts 'hey' end end 

test_test.rb

 require 'minitest/spec' require 'minitest/autorun' require_relative 'testclass' class TestTestClass < MiniTest::Unit::TestCase def setup @test = TestClass.new end def output_produces_output assert_output( stdout = 'hey' ) { @test.output} end end 

I get:

Ready tests in 0.000000s, NaN / s tests, NaN statements

0 tests, 0 statements, 0 errors, 0 errors, 0 omissions

What am I doing wrong? It should be something completely obvious, but I can't figure it out. Thank you for your help.

+6
source share
1 answer

In order for your test method to run, the method name must begin with test_ . In addition, the assert_output method is to write the block to stdout / stderr, and the arguments will be checked if they match stdout / stderr. The easiest way to test this IMO is to pass to regex. So this is how I will write this test:

 class TestTestClass < MiniTest::Unit::TestCase def setup @test = TestClass.new end def test_output_produces_output assert_output(/hey/) { @test.output} end end 
+10
source

Source: https://habr.com/ru/post/978000/


All Articles