class RuboCop::Cop::Minitest::AssertOutput


assert_output(expected) { puts object.method }
# good
assert_match expected, $stdout.read
$stdout.rewind
puts object.method
$stdout = StringIO.new
# bad
@example
Checks for opportunities to use ‘assert_output`.

def find_test_case(node)

def find_test_case(node)
  node.each_ancestor.find { |ancestor| test_case?(ancestor) }
end

def on_gvasgn(node)

def on_gvasgn(node)
  test_case_node = find_test_case(node)
  return unless test_case_node
  gvar_name = node.children.first
  return unless OUTPUT_GLOBAL_VARIABLES.include?(gvar_name)
  assertions(test_case_node).each do |assertion|
    add_offense(assertion, message: format(MSG, name: gvar_name)) if references_gvar?(assertion, gvar_name)
  end
end

def references_gvar?(assertion, gvar_name)

def references_gvar?(assertion, gvar_name)
  assertion.each_descendant(:gvar).any? { |d| d.children.first == gvar_name }
end