Permalink
Browse files

Correctly output the name of the object being profiled with its report.

  • Loading branch information...
1 parent 2c4cdf2 commit b6c569d87917ca5319a5f3568cb192a811208bd0 @jimmycuadra jimmycuadra committed Feb 14, 2013
Showing with 10 additions and 3 deletions.
  1. +1 −1 lib/method_profiler/profiler.rb
  2. +4 −2 lib/method_profiler/report.rb
  3. +4 −0 spec/method_profiler/report_spec.rb
  4. +1 −0 spec/spec_helper.rb
@@ -25,7 +25,7 @@ def initialize(obj)
# @return [Report] A new report with all the data the profiler has collected.
#
def report
- Report.new(final_data)
+ Report.new(final_data, @obj.name)
end
private
@@ -24,9 +24,11 @@ class Report
# Initializes a new {Report}. Used to sort and display data collected by a {Profiler}.
#
# @param [Array] data Data collected by a {Profiler}.
+ # @param [String] name The name of the object that was profiled.
#
- def initialize(data)
+ def initialize(data, name)
@data = data
+ @name = name
@sort_by = :average
@order = :descending
end
@@ -75,7 +77,7 @@ def to_a
#
def to_s
[
- "MethodProfiler results for: #{@obj}",
+ "MethodProfiler results for: #{@name}",
Hirb::Helpers::Table.render(
to_a,
headers: HEADERS.dup,
@@ -71,6 +71,10 @@
end
describe "#to_s" do
+ it "displays the name of the profiled object" do
+ @report.to_s.should include("MethodProfiler results for: Petition")
+ end
+
it "outputs one line for each method that was called" do
output = @report.to_s
View
@@ -1,4 +1,5 @@
require "simplecov"
+SimpleCov.add_filter "spec"
SimpleCov.start
$:.unshift(File.expand_path("../../lib", __FILE__))

0 comments on commit b6c569d

Please sign in to comment.