Skip to content

Commit

Permalink
Merge pull request #351 from getappmap/minitest-tagz_20240130
Browse files Browse the repository at this point in the history
Minitest tagz 20240130
  • Loading branch information
apotterri authored Feb 5, 2024
2 parents 1b2aa23 + 0278ad9 commit 93198b5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/appmap/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,24 @@ def begin_test(test, name)

@recording_count += 1

@recordings_by_test[test.object_id] = Recording.new(test, name)
recording = if defined?(::Minitest::Tagz) && disabled_by_tag(test, name)
:disabled
else
Recording.new(test, name)
end
@recordings_by_test[test.object_id] = recording
end

def disabled_by_tag(test, name)
tags = ::Minitest::Tagz.tag_map[::Minitest::Tagz.serialize(test.class, name)]
tags && tags.include?("noappmap")
end

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

recording.finish test.failures || [], exception
recording.finish test.failures || [], exception unless recording == :disabled
end

def config
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/minitest_recorder/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ source 'https://rubygems.org'
gem 'appmap', git: 'applandinc/appmap-ruby', branch: `git rev-parse --abbrev-ref HEAD`.strip
gem 'byebug'
gem 'minitest'

gem 'minitest-tagz'
19 changes: 19 additions & 0 deletions test/fixtures/minitest_recorder/test/hello_tagged_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'test_helper'

require 'minitest/autorun'
require 'appmap/minitest'
require 'hello'

class HelloTaggedTest < ::Minitest::Test
tag :noappmap
def test_tagged
assert_equal 'Hello!', Hello.new.say_hello
end

def test_untagged
assert_equal 'Hello!', Hello.new.say_hello
end
end
2 changes: 2 additions & 0 deletions test/fixtures/minitest_recorder/test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'minitest/tagz'
Minitest::Tagz.choose_tags(*ENV['TAGS'].split(',')) if ENV['TAGS']
12 changes: 12 additions & 0 deletions test/minitest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,16 @@ def test_failed
assert_equal test_failure['location'], 'test/hello_failed_test.rb:10'
end
end

def test_noappmap_tag
perform_minitest_test 'hello_tagged' do
# Sanity check, make sure the test file was executed
appmap_file = 'tmp/appmap/minitest/Hello_tagged_untagged.appmap.json'
assert File.file?(appmap_file), 'appmap output file does not exist'

# The test tagged with :noappmap should not have generated an AppMap
appmap_file = 'tmp/appmap/minitest/Hello_tagged_tagged.appmap.json'
assert !File.file?(appmap_file), 'test tagged :noappmap generated an AppMap'
end
end
end

0 comments on commit 93198b5

Please sign in to comment.