How to get the name of a test run as part of a setup or break callback?

I would like to add performance warnings to our tests, for example:

# in test_helper.rb class ActiveSupport::TestCase def record_test_start_time @test_start_time = Time.now end setup :record_test_start_time def warn_long_running_test running_time = Time.now - @test_start_time if running_time > 10.seconds puts "WARNING: Test #{test_name} ran for #{running_time}" end end setup :record_test_start_time end 

How to get test name in test_name variable? I have had poor results using Kernel # caller from setup / break callbacks in the past.

+4
source share
2 answers

The name method gives you the string "method name (class name)", and I think @method_name gives the name of the current test.

+1
source

This is currently the method_name method.

+3
source

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


All Articles