From 481ee8e2c23a9b33df6af71adc9c940a28255bf7 Mon Sep 17 00:00:00 2001 From: Alex Gusev Date: Tue, 28 May 2013 12:39:19 +0400 Subject: [PATCH] Conditioned profiling --- lib/pilfer/profiler.rb | 8 ++++++++ spec/pilfer/profiler_spec.rb | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/lib/pilfer/profiler.rb b/lib/pilfer/profiler.rb index d55b726..5eb1f06 100644 --- a/lib/pilfer/profiler.rb +++ b/lib/pilfer/profiler.rb @@ -12,6 +12,14 @@ def profile(*args, &app) profile_files_matching(/./, *args, &app) end + def profile_if(*args, &app) + if args.shift + profile(*args, &app) + else + app.call + end + end + def profile_files_matching(matcher, description = nil, reporter_options = {}, profiler = method(:lineprof), diff --git a/spec/pilfer/profiler_spec.rb b/spec/pilfer/profiler_spec.rb index 5571e79..1cd448f 100644 --- a/spec/pilfer/profiler_spec.rb +++ b/spec/pilfer/profiler_spec.rb @@ -33,6 +33,12 @@ Pilfer::Profiler.new(reporter). profile(description, reporter_options, profiler, start) { } end + + it 'should not run if conditioned and condition is false' do + reporter.should_not_receive(:write) + Pilfer::Profiler.new(reporter). + profile_if(false, description, reporter_options, profiler, start) { } + end end describe '#profile_files_matching' do