diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2015-12-10 16:25:28 +0100 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2015-12-17 17:25:48 +0100 |
commit | 641761f1d6af5a94c0007e8d7463ee86fc047229 (patch) | |
tree | fb93d01f675fe706cfec0912b4baff839c25dd24 /spec/lib/gitlab/metrics | |
parent | f43f3b89a633b5ceee4e71acba0c83ed5cb28963 (diff) | |
download | gitlab-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.rb | 26 |
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 |