Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Display slow tests occupied time #602

Merged
merged 5 commits into from Apr 18, 2012
@@ -53,7 +53,10 @@ def dump_commands_to_rerun_failed_examples
def dump_profile
sorted_examples = examples.sort_by { |example| example.execution_result[:run_time] }.reverse.first(10)
- output.puts "\nTop #{sorted_examples.size} slowest examples:\n"
+
+ total, slows = [examples, sorted_examples].map {|exs| exs.inject(0.0) {|i, e| i + e.execution_result[:run_time] } }
+ output.puts "\nTop #{sorted_examples.size} slowest examples (#{format_seconds(slows)} seconds, taken #{((slows / total) * 100).round(2)}% of total time):\n"
+
sorted_examples.each do |example|
output.puts " #{example.full_description}"
output.puts cyan(" #{red(format_seconds(example.execution_result[:run_time]))} #{red("seconds")} #{format_caller(example.location)}")
@@ -321,13 +321,12 @@ def run_all_and_dump_pending
describe "#dump_profile" do
before do
- formatter.stub(:examples) do
- group = RSpec::Core::ExampleGroup.describe("group") do
- example("example")
- end
- group.run(double('reporter').as_null_object)
- group.examples
+ group = RSpec::Core::ExampleGroup.describe("group") do
+ example("example")
end
+ group.run(double('reporter').as_null_object)
+
+ formatter.stub(:examples) { group.examples }
end
it "names the example" do
@@ -346,5 +345,10 @@ def run_all_and_dump_pending
output.string.should =~ /#{filename}\:#{__LINE__ - 21}/
end
+
+ it "prints ocuppied time" do
+ formatter.dump_profile
+ output.string.should =~ /Top 1 slowest examples \(0(\.\d+)? seconds, taken 100.0% of total time\):/
+ end
end
end