Skip to content

Commit 0278ad9

Browse files
committed
feat: disable recording for tests tagged :noappmap
Check to see if Minitest::Tagz has been used to add the tag :noappmap to a test method. If so, don't generate an AppMap for the test. BREAKING CHANGE: bump to version 1.0.0
1 parent 1b2aa23 commit 0278ad9

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

lib/appmap/minitest.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,24 @@ def begin_test(test, name)
8585

8686
@recording_count += 1
8787

88-
@recordings_by_test[test.object_id] = Recording.new(test, name)
88+
recording = if defined?(::Minitest::Tagz) && disabled_by_tag(test, name)
89+
:disabled
90+
else
91+
Recording.new(test, name)
92+
end
93+
@recordings_by_test[test.object_id] = recording
94+
end
95+
96+
def disabled_by_tag(test, name)
97+
tags = ::Minitest::Tagz.tag_map[::Minitest::Tagz.serialize(test.class, name)]
98+
tags && tags.include?("noappmap")
8999
end
90100

91101
def end_test(test, exception:)
92102
recording = @recordings_by_test.delete(test.object_id)
93103
return warn "No recording found for #{test}" unless recording
94104

95-
recording.finish test.failures || [], exception
105+
recording.finish test.failures || [], exception unless recording == :disabled
96106
end
97107

98108
def config

test/fixtures/minitest_recorder/Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ source 'https://rubygems.org'
33
gem 'appmap', git: 'applandinc/appmap-ruby', branch: `git rev-parse --abbrev-ref HEAD`.strip
44
gem 'byebug'
55
gem 'minitest'
6+
7+
gem 'minitest-tagz'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require 'test_helper'
5+
6+
require 'minitest/autorun'
7+
require 'appmap/minitest'
8+
require 'hello'
9+
10+
class HelloTaggedTest < ::Minitest::Test
11+
tag :noappmap
12+
def test_tagged
13+
assert_equal 'Hello!', Hello.new.say_hello
14+
end
15+
16+
def test_untagged
17+
assert_equal 'Hello!', Hello.new.say_hello
18+
end
19+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require 'minitest/tagz'
2+
Minitest::Tagz.choose_tags(*ENV['TAGS'].split(',')) if ENV['TAGS']

test/minitest_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,16 @@ def test_failed
5151
assert_equal test_failure['location'], 'test/hello_failed_test.rb:10'
5252
end
5353
end
54+
55+
def test_noappmap_tag
56+
perform_minitest_test 'hello_tagged' do
57+
# Sanity check, make sure the test file was executed
58+
appmap_file = 'tmp/appmap/minitest/Hello_tagged_untagged.appmap.json'
59+
assert File.file?(appmap_file), 'appmap output file does not exist'
60+
61+
# The test tagged with :noappmap should not have generated an AppMap
62+
appmap_file = 'tmp/appmap/minitest/Hello_tagged_tagged.appmap.json'
63+
assert !File.file?(appmap_file), 'test tagged :noappmap generated an AppMap'
64+
end
65+
end
5466
end

0 commit comments

Comments
 (0)