diff --git a/Gemfile b/Gemfile index 4229b05..caa40ac 100644 --- a/Gemfile +++ b/Gemfile @@ -1,14 +1,14 @@ source 'https://rubygems.org' gemspec -gem 'stackprof', platforms: :mri_21 + +gem 'stackprof', platforms: :mri group :benchmark, :test do gem 'benchmark-ips' end group :test do - gem 'spy', '0.4.1' gem 'rubocop', '0.34.2' platform :mri do diff --git a/test/test_helper.rb b/test/test_helper.rb index b8e4d9a..ac5ab53 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,7 +2,6 @@ ENV["MT_NO_EXPECTATIONS"] = "1" require 'minitest/autorun' -require 'spy/integration' $LOAD_PATH.unshift(File.join(File.expand_path(__dir__), '..', 'lib')) require 'liquid.rb' diff --git a/test/unit/context_unit_test.rb b/test/unit/context_unit_test.rb index d60aae3..fab19b8 100644 --- a/test/unit/context_unit_test.rb +++ b/test/unit/context_unit_test.rb @@ -70,10 +70,6 @@ class ContextUnitTest < Minitest::Test @context = Liquid::Context.new end - def teardown - Spy.teardown - end - def test_variables @context['string'] = 'string' assert_equal 'string', @context['string'] @@ -450,14 +446,10 @@ class ContextUnitTest < Minitest::Test assert_equal @context, @context['category'].context end - def test_use_empty_instead_of_any_in_interrupt_handling_to_avoid_lots_of_unnecessary_object_allocations - mock_any = Spy.on_instance_method(Array, :any?) - mock_empty = Spy.on_instance_method(Array, :empty?) - - @context.interrupt? - - refute mock_any.has_been_called? - assert mock_empty.has_been_called? + def test_interrupt_avoids_object_allocations + assert_no_object_allocations do + @context.interrupt? + end end def test_context_initialization_with_a_proc_in_environment @@ -480,4 +472,18 @@ class ContextUnitTest < Minitest::Test context = Context.new assert_equal 'hi', context.apply_global_filter('hi') end + + private + + def assert_no_object_allocations + unless RUBY_ENGINE == 'ruby' + skip "stackprof needed to count object allocations" + end + require 'stackprof' + + profile = StackProf.run(mode: :object) do + yield + end + assert_equal 0, profile[:samples] + end end # ContextTest