diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2015-10-05 11:51:24 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2015-10-05 11:51:24 +0300 |
commit | 22506ddc50146ab56b2f114d90ab7b3270d60de1 (patch) | |
tree | 78a9c488147de3f0f2dfe9fb0f3ee5f2fa001df0 /spec/support | |
parent | 19893a1c10e4e6dfbdb56ad78de1599b6c8f6981 (diff) |
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/support')
-rw-r--r-- | spec/support/matchers/benchmark_matchers.rb | 17 |
1 files changed, 17 insertions, 0 deletions
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 |