summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/metrics
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2015-12-10 16:25:28 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2015-12-17 17:25:48 +0100
commit641761f1d6af5a94c0007e8d7463ee86fc047229 (patch)
treefb93d01f675fe706cfec0912b4baff839c25dd24 /spec/lib/gitlab/metrics
parentf43f3b89a633b5ceee4e71acba0c83ed5cb28963 (diff)
downloadgitlab-ce-641761f1d6af5a94c0007e8d7463ee86fc047229.tar.gz
Only instrument methods defined directly
When using instrument_methods/instrument_instance_methods we only want to instrument methods defined directly in a class, not those included via mixins (e.g. whatever RSpec throws in during development). In case an externally included method _has_ to be instrumented we can still use the regular instrument_method/instrument_instance_method methods.
Diffstat (limited to 'spec/lib/gitlab/metrics')
-rw-r--r--spec/lib/gitlab/metrics/instrumentation_spec.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/lib/gitlab/metrics/instrumentation_spec.rb b/spec/lib/gitlab/metrics/instrumentation_spec.rb
index fdb0820b875..80dc160ebd2 100644
--- a/spec/lib/gitlab/metrics/instrumentation_spec.rb
+++ b/spec/lib/gitlab/metrics/instrumentation_spec.rb
@@ -119,6 +119,19 @@ describe Gitlab::Metrics::Instrumentation do
expect(@dummy).to respond_to(:_original_foo)
end
+
+ it 'only instruments methods directly defined in the module' do
+ mod = Module.new do
+ def kittens
+ end
+ end
+
+ @dummy.extend(mod)
+
+ described_class.instrument_methods(@dummy)
+
+ expect(@dummy).to_not respond_to(:_original_kittens)
+ end
end
describe '.instrument_instance_methods' do
@@ -131,5 +144,18 @@ describe Gitlab::Metrics::Instrumentation do
expect(@dummy.method_defined?(:_original_bar)).to eq(true)
end
+
+ it 'only instruments methods directly defined in the module' do
+ mod = Module.new do
+ def kittens
+ end
+ end
+
+ @dummy.include(mod)
+
+ described_class.instrument_instance_methods(@dummy)
+
+ expect(@dummy.method_defined?(:_original_kittens)).to eq(false)
+ end
end
end