summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/benchmarks/models/user_spec.rb8
-rw-r--r--spec/support/matchers/benchmark_matchers.rb17
2 files changed, 21 insertions, 4 deletions
diff --git a/spec/benchmarks/models/user_spec.rb b/spec/benchmarks/models/user_spec.rb
index a08c84ffce4..168be20b7a5 100644
--- a/spec/benchmarks/models/user_spec.rb
+++ b/spec/benchmarks/models/user_spec.rb
@@ -14,25 +14,25 @@ describe User, benchmark: true do
let(:iterations) { 1000 }
describe 'using a capitalized username' do
- subject { -> { User.by_login('Alice') } }
+ benchmark_subject { User.by_login('Alice') }
it { is_expected.to iterate_per_second(iterations) }
end
describe 'using a lowercase username' do
- subject { -> { User.by_login('alice') } }
+ benchmark_subject { User.by_login('alice') }
it { is_expected.to iterate_per_second(iterations) }
end
describe 'using a capitalized Email address' do
- subject { -> { User.by_login('Alice@gitlab.com') } }
+ benchmark_subject { User.by_login('Alice@gitlab.com') }
it { is_expected.to iterate_per_second(iterations) }
end
describe 'using a lowercase Email address' do
- subject { -> { User.by_login('alice@gitlab.com') } }
+ benchmark_subject { User.by_login('alice@gitlab.com') }
it { is_expected.to iterate_per_second(iterations) }
end
diff --git a/spec/support/matchers/benchmark_matchers.rb b/spec/support/matchers/benchmark_matchers.rb
index 45a1d49345f..b73a53917f0 100644
--- a/spec/support/matchers/benchmark_matchers.rb
+++ b/spec/support/matchers/benchmark_matchers.rb
@@ -1,6 +1,10 @@
module BenchmarkMatchers
extend RSpec::Matchers::DSL
+ def self.included(into)
+ into.extend(ClassMethods)
+ end
+
matcher :iterate_per_second do |min_iterations|
supports_block_expectations
@@ -39,4 +43,17 @@ module BenchmarkMatchers
report.entries[0]
end
+
+ module ClassMethods
+ # Wraps around rspec's subject method so you can write:
+ #
+ # benchmark_subject { SomeClass.some_method }
+ #
+ # instead of:
+ #
+ # subject { -> { SomeClass.some_method } }
+ def benchmark_subject(&block)
+ subject { block }
+ end
+ end
end