unit testing - Ruby minitest assert_output syntax -
unit testing - Ruby minitest assert_output syntax -
i new minitest , still new ruby , tired of trying google question without result. grateful help:
what exact syntax of assert_output in ruby minitest?
all find on github or elsewhere seems utilize parentheses. yet, error message when don't utilize block assert_output, makes sense definition of method contains yield statement.
but cannot create work, whatever 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
what is:
finished tests in 0.000000s, nan tests/s, nan assertions
0 tests, 0 assertions, 0 failures, 0 errors, 0 skips
what doing wrong? must totally obvious, cannot figure out. help.
in order test method run, method name needs start test_
. also, way assert_output
works block write stdout/stderr, , arguments checked if match stdout/stderr. easiest way check imo pass in regexp. how write test:
class testtestclass < minitest::unit::testcase def setup @test = testclass.new end def test_output_produces_output assert_output(/hey/) { @test.output} end end
ruby unit-testing minitest assertions
Comments
Post a Comment