diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 92ec5f6f9..37792ffd5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -49,6 +49,7 @@ module ApplicationHelper end buf << [ javascript_include_tag('jquery_ujs') ] buf << [ javascript_tag("jQuery.ajaxSetup({'cache': false});") ] + buf << [ javascript_tag("$.fx.off = true;") ] if Rails.env.test? buf.join("\n").html_safe end end diff --git a/features/support/env.rb b/features/support/env.rb index e61502c7f..0523ff9a0 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -100,3 +100,12 @@ Spork.each_run do CapybaraSettings.instance.restore end end + +# https://makandracards.com/makandra/950-speed-up-rspec-by-deferring-garbage-collection +require File.join(File.dirname(__FILE__), "..", "..", "spec", "support", "deferred_garbage_collection") +Before do + DeferredGarbageCollection.start +end +After do + DeferredGarbageCollection.reconsider +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 28529a8a9..a0bfa718c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -101,3 +101,13 @@ Spork.each_run do AppConfig.load! AppConfig.setup! end + +# https://makandracards.com/makandra/950-speed-up-rspec-by-deferring-garbage-collection +RSpec.configure do |config| + config.before(:all) do + DeferredGarbageCollection.start + end + config.after(:all) do + DeferredGarbageCollection.reconsider + end +end diff --git a/spec/support/deferred_garbage_collection.rb b/spec/support/deferred_garbage_collection.rb new file mode 100644 index 000000000..5be5a45d1 --- /dev/null +++ b/spec/support/deferred_garbage_collection.rb @@ -0,0 +1,22 @@ + +# https://makandracards.com/makandra/950-speed-up-rspec-by-deferring-garbage-collection +class DeferredGarbageCollection + + DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || 10.0).to_f + + @@last_gc_run = Time.now + + def self.start + GC.disable if DEFERRED_GC_THRESHOLD > 0 + end + + def self.reconsider + if DEFERRED_GC_THRESHOLD > 0 && Time.now - @@last_gc_run >= DEFERRED_GC_THRESHOLD + GC.enable + GC.start + GC.disable + @@last_gc_run = Time.now + end + end + +end