Skip to content
Browse files

Ensure #profile returns the value of the real method.

  • Loading branch information...
1 parent a318af2 commit e78a1db261e5ed6e75b8251aadf3cfb69de24e9b @jimmycuadra jimmycuadra committed Mar 1, 2012
Showing with 8 additions and 2 deletions.
  1. +3 −1 lib/method_profiler.rb
  2. +4 −0 spec/method_profiler_spec.rb
  3. +1 −1 spec/spec_helper.rb
View
4 lib/method_profiler.rb
@@ -12,9 +12,11 @@ def initialize(obj)
end
def profile(method, &block)
- benchmark = Benchmark.measure { block.call }
+ result = nil
+ benchmark = Benchmark.measure { result = block.call }
elapsed_time = benchmark.to_s.match(/\(\s*([^\)]+)\)/)[1].to_f
@data[method.to_sym] << elapsed_time
+ result
end
def report
View
4 spec/method_profiler_spec.rb
@@ -31,6 +31,10 @@
@petition.should_receive(:foo_without_profiling)
@petition.foo
end
+
+ it "returns the value of the real method" do
+ @petition.baz.should == "blah"
+ end
end
describe "#report" do
View
2 spec/spec_helper.rb
@@ -4,5 +4,5 @@
class Petition
def foo; end
def bar; end
- def baz; end
+ def baz; "blah"; end
end

0 comments on commit e78a1db

Please sign in to comment.
Something went wrong with that request. Please try again.