diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-07-20 16:06:11 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-07-20 16:06:11 +0300 |
commit | 33e11345e086678fce7591bcd1d465f879d838e7 (patch) | |
tree | d3faea3c4bead6c5080876ccb6c39e42683ef84d /spec/support | |
parent | ac4b954c5fabbfa98fb72d88526a30713a20af5d (diff) |
Add custom expectations for authentication activity metrics
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/helpers/stub_configuration.rb | 11 | ||||
-rw-r--r-- | spec/support/prometheus/custom_matchers.rb | 8 |
2 files changed, 16 insertions, 3 deletions
diff --git a/spec/support/helpers/stub_configuration.rb b/spec/support/helpers/stub_configuration.rb index 1823099dd9c..eb9a884e350 100644 --- a/spec/support/helpers/stub_configuration.rb +++ b/spec/support/helpers/stub_configuration.rb @@ -68,6 +68,17 @@ module StubConfiguration allow(Gitlab.config.repositories).to receive(:storages).and_return(Settingslogic.new(messages)) end + def authentication_metrics + Gitlab::Auth::Activity + end + + def stub_authentication_activity_metrics + authentication_metrics.each_counter do |counter, metric, description| + allow(authentication_metrics).to receive(counter) + .and_return(spy("#{metric} - #{description}")) + end + end + private # Modifies stubbed messages to also stub possible predicate versions diff --git a/spec/support/prometheus/custom_matchers.rb b/spec/support/prometheus/custom_matchers.rb index 2ad3b8a7fce..21d5fd3e6ff 100644 --- a/spec/support/prometheus/custom_matchers.rb +++ b/spec/support/prometheus/custom_matchers.rb @@ -1,5 +1,7 @@ -RSpec::Matchers.define :increment do |counter| - match do |metric| - expect(metric.send(counter)).to receive(:increment) +RSpec::Matchers.define :have_incremented do |counter| + match do |adapter| + matcher = RSpec::Mocks::Matchers::HaveReceived.new(:increment) + + matcher.matches?(adapter.send(counter)) end end |