summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/metrics/instrumentation_spec.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-01-25 21:26:49 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2016-01-25 21:28:59 +0100
commitb74308c0a74ce9256bfe906a070b8751d2cc9e9e (patch)
treecd64d2dcedfcc40fd432bd31aef91def66274ec4 /spec/lib/gitlab/metrics/instrumentation_spec.rb
parent8b3285bfdffc3ee6a2fbd65a8d7981214344deda (diff)
downloadgitlab-ce-b74308c0a74ce9256bfe906a070b8751d2cc9e9e.tar.gz
Correct arity for instrumented methods w/o argsinstrumentation-signature
This ensures that an instrumented method that doesn't take arguments reports an arity of 0, instead of -1. If Ruby had a proper method for finding out the required arguments of a method (e.g. Method#required_arguments) this would not have been an issue. Sadly the only two methods we have are Method#parameters and Method#arity, and both are equally painful to use. Fixes gitlab-org/gitlab-ce#12450
Diffstat (limited to 'spec/lib/gitlab/metrics/instrumentation_spec.rb')
-rw-r--r--spec/lib/gitlab/metrics/instrumentation_spec.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/spec/lib/gitlab/metrics/instrumentation_spec.rb b/spec/lib/gitlab/metrics/instrumentation_spec.rb
index 2a37cd40dde..ad4290c43bb 100644
--- a/spec/lib/gitlab/metrics/instrumentation_spec.rb
+++ b/spec/lib/gitlab/metrics/instrumentation_spec.rb
@@ -66,6 +66,16 @@ describe Gitlab::Metrics::Instrumentation do
@dummy.foo
end
+
+ it 'generates a method with the correct arity when using methods without arguments' do
+ dummy = Class.new do
+ def self.test; end
+ end
+
+ described_class.instrument_method(dummy, :test)
+
+ expect(dummy.method(:test).arity).to eq(0)
+ end
end
describe 'with metrics disabled' do