Skip to content

Commit

Permalink
Merge pull request #1476 from ruby/print-skip-message
Browse files Browse the repository at this point in the history
Improve skip test message
  • Loading branch information
soutaro authored Aug 29, 2023
2 parents da1534f + bbae2ea commit 62dec3d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
19 changes: 13 additions & 6 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,22 @@ def assert_sampling_check(builder, sample_size, array)
OptionParser.new do |opts|
opts.on("--name NAME") do |name|
name = name.gsub(/(\A\/)|(\/\Z)/, '')
klass_name, method_name = name.split("#", 2)

constant = (Object.const_get(name) rescue nil)
constant = ObjectSpace.each_object(Class).find do |klass|
if klass.name
klass.name == klass_name || klass.name.end_with?("::#{klass_name}")
end
end

if constant
test_unit_args << "--testcase"
test_unit_args << name
else
test_unit_args << "--name"
test_unit_args << name
if method_name
test_unit_args << "--name"
test_unit_args << "#{constant.name}##{method_name}"
else
test_unit_args << "--testcase"
test_unit_args << constant.name
end
end
end
end.order!(argv)
Expand Down
5 changes: 4 additions & 1 deletion test/test_skip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ def setup
end

def teardown
unless current_result.passed?
case
when passed?
# nop
else
puts "💡You can skip this test `#{name}` by adding the name to `#{SKIP_TESTS_FILE}`"
end

Expand Down

0 comments on commit 62dec3d

Please sign in to comment.