THIRFT-5367 Fix crashes when using Ruby compaction GC
Client: rb
Patch: Stan Hu

This closes #2347
diff --git a/lib/rb/spec/spec_helper.rb b/lib/rb/spec/spec_helper.rb
index 5bf98d0..7c16507 100644
--- a/lib/rb/spec/spec_helper.rb
+++ b/lib/rb/spec/spec_helper.rb
@@ -62,3 +62,8 @@
 
 $:.unshift File.join(File.dirname(__FILE__), *%w[gen-rb/flat])
 
+if defined?(GC.verify_compaction_references) == 'method'
+  # This method was added in Ruby 3.0.0. Calling it this way asks the GC to
+  # move objects around, helping to find object movement bugs.
+  GC.verify_compaction_references(double_heap: true, toward: :empty)
+end