diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2015-10-05 10:51:24 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2015-10-05 10:51:24 +0200 |
commit | 22506ddc50146ab56b2f114d90ab7b3270d60de1 (patch) | |
tree | 78a9c488147de3f0f2dfe9fb0f3ee5f2fa001df0 /spec | |
parent | 19893a1c10e4e6dfbdb56ad78de1599b6c8f6981 (diff) | |
download | gitlab-ce-22506ddc50146ab56b2f114d90ab7b3270d60de1.tar.gz |
Added benchmark_subject method for benchmarks
This class method can be used in "describe" blocks to specify the
subject of a benchmark. This lets you write:
benchmark_subject { Foo }
instead of:
benchmark_subject { -> { Foo } }
Diffstat (limited to 'spec')
-rw-r--r-- | spec/benchmarks/models/user_spec.rb | 8 | ||||
-rw-r--r-- | spec/support/matchers/benchmark_matchers.rb | 17 |
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 |