Skip to content

Commit

Permalink
Mark methods called by ActiveSupport::TestCase.setup as alive
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
  • Loading branch information
Morriar committed Mar 12, 2024
1 parent 0111c79 commit a04f375
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/spoom/deadcode/plugins/active_support.rb
Expand Up @@ -15,6 +15,17 @@ class ActiveSupport < Base
"before_setup",
"before_teardown",
)

SETUP_AND_TEARDOWN_METHODS = T.let(["setup", "teardown"], T::Array[String])

sig { override.params(indexer: Indexer, send: Send).void }
def on_send(indexer, send)
return unless send.recv.nil? && SETUP_AND_TEARDOWN_METHODS.include?(send.name)

send.each_arg(SyntaxTree::SymbolLiteral) do |arg|
indexer.reference_method(indexer.node_string(arg.value), send.node)
end
end
end
end
end
Expand Down
42 changes: 42 additions & 0 deletions test/spoom/deadcode/plugins/active_support_test.rb
@@ -0,0 +1,42 @@
# typed: true
# frozen_string_literal: true

require "test_with_project"
require "helpers/deadcode_helper"

module Spoom
module Deadcode
module Plugins
class ActiveSupportTest < TestWithProject
include Test::Helpers::DeadcodeHelper

def test_ignore_minitest_setup_and_teardown_with_symbols
@project.write!("test/foo_test.rb", <<~RB)
class FooTest
setup(:alive1, :alive2)
teardown(:alive3)
def alive1; end
def alive2; end
def alive3; end
def dead; end
end
RB

index = index_with_plugins
assert_alive(index, "alive1")
assert_alive(index, "alive2")
assert_alive(index, "alive3")
assert_dead(index, "dead")
end

private

sig { returns(Index) }
def index_with_plugins
deadcode_index(plugins: [ActiveSupport.new])
end
end
end
end
end

0 comments on commit a04f375

Please sign in to comment.