From d263248050ed880349d146e38dd5aef63003ca72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Coutable?= <remy@rymai.me>
Date: Thu, 4 May 2017 18:38:34 +0200
Subject: [PATCH] Monkey-patch Knapsack to include context duration in reports
 for PG
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Rémy Coutable <remy@rymai.me>
---
 spec/spec_helper.rb | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index e2d5928e5b2..13fcf632f15 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -24,6 +24,40 @@ end
 if ENV['CI'] && !ENV['NO_KNAPSACK']
   require 'knapsack'
   Knapsack::Adapters::RSpecAdapter.bind
+
+  if ENV['GITLAB_DATABASE'] == 'postgresql'
+    module Knapsack
+      module Adapters
+        class RSpecAdapter < BaseAdapter
+          def bind_time_tracker
+            ::RSpec.configure do |config|
+              config.before(:context) do
+                Knapsack.tracker.start_timer
+              end
+
+              config.before(:each) do
+                current_example_group =
+                  if ::RSpec.respond_to?(:current_example)
+                    ::RSpec.current_example.metadata[:example_group]
+                  else
+                    example.metadata
+                  end
+                Knapsack.tracker.test_path = RSpecAdapter.test_path(current_example_group)
+              end
+
+              config.after(:context) do
+                Knapsack.tracker.stop_timer
+              end
+
+              config.after(:suite) do
+                Knapsack.logger.info(Presenter.global_time)
+              end
+            end
+          end
+        end
+      end
+    end
+  end
 end
 
 # Requires supporting ruby files with custom matchers and macros, etc,
-- 
GitLab