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

Reporting load time to formatters #841

Closed
wants to merge 6 commits into
from
@@ -170,6 +170,9 @@ def self.add_setting(name, opts={})
# end
add_setting :treat_symbols_as_metadata_keys_with_true_values
+ # Record the start time of the spec suite to measure load time
+ add_setting :start_time
+
# @private
add_setting :tty
# @private
@@ -184,6 +187,7 @@ def self.add_setting(name, opts={})
attr_reader :backtrace_cleaner
def initialize
+ @start_time = Time.now
@expectation_frameworks = []
@include_or_extend_modules = []
@mock_framework = nil
@@ -13,7 +13,7 @@ module Formatters
class BaseFormatter
include Helpers
attr_accessor :example_group
- attr_reader :duration, :examples, :output
+ attr_reader :duration, :examples, :output, :load_time
attr_reader :example_count, :pending_count, :failure_count
attr_reader :failed_examples, :pending_examples
@@ -27,6 +27,7 @@ def initialize(output)
@failed_examples = []
@pending_examples = []
@example_group = nil
+ @load_time = 0
end
# @api public
@@ -39,9 +40,10 @@ def initialize(output)
# is {#example_group_started}.
#
# @param example_count
- def start(example_count)
+ def start(example_count, load_time)
start_sync_output
@example_count = example_count
+ @load_time = load_time
end
# @api public
@@ -45,7 +45,7 @@ def colorise_summary(summary)
def dump_summary(duration, example_count, failure_count, pending_count)
super(duration, example_count, failure_count, pending_count)
dump_profile unless mute_profile_output?(failure_count)
- output.puts "\nFinished in #{format_duration(duration)}\n"
+ output.puts "\nFinished in #{format_duration(duration)} (Files took #{format_duration(load_time)} to load)\n"
output.puts colorise_summary(summary_line(example_count, failure_count, pending_count))
dump_commands_to_rerun_failed_examples
end
@@ -33,8 +33,8 @@ def example_number
@example_number
end
- def start(example_count)
- super(example_count)
+ def start(example_count, load_time)
+ super(example_count, load_time)
@printer.print_html_start
@printer.flush
end
@@ -37,9 +37,10 @@ def report(expected_example_count, seed=nil)
end
end
- def start(expected_example_count)
- @start = RSpec::Core::Time.now
- notify :start, expected_example_count
+ def start(expected_example_count, time = RSpec::Core::Time.now)
+ @start = time
+ load_time = (@start - RSpec.configuration.start_time).to_f
+ notify :start, expected_example_count, load_time
end
def message(message)
@@ -1516,5 +1516,16 @@ def metadata_hash(*args)
expect(groups.ordered).to eq([4, 3, 2, 1])
end
end
+
+ describe 'recording spec start time (for measuring load)' do
+ it 'returns a time' do
+ expect(config.start_time).to be_a Time
+ end
+ it 'is configuratble' do
+ time = Time.new - 5
+ config.start_time = time
+ expect(config.start_time).to eq time
+ end
+ end
end
end
@@ -26,6 +26,20 @@
end
end
+ describe "start" do
+ before do
+ formatter.start 42, 3.234
+ end
+
+ it 'has captured example_count' do
+ expect(formatter.example_count).to eq 42
+ end
+
+ it 'has captured load_time' do
+ expect(formatter.load_time).to eq 3.234
+ end
+ end
+
describe "read_failed_line" do
it "deals gracefully with a heterogeneous language stack trace" do
exception = double(:Exception, :backtrace => [
@@ -6,7 +6,7 @@
before do
@output = StringIO.new
@formatter = RSpec::Core::Formatters::ProgressFormatter.new(@output)
- @formatter.start(2)
+ @formatter.start(2, 0)
@formatter.stub(:color_enabled?).and_return(false)
end
@@ -23,7 +23,7 @@
end
it "pushes nothing on start" do
- @formatter.start(4)
+ @formatter.start(4, 0)
expect(@output.string).to eq("")
end
@@ -15,6 +15,18 @@ module RSpec::Core
end
end
+ describe 'start' do
+ it 'notifies the formatter of start with example count and load time' do
+ formatter = double("formatter")
+ example = double("example")
+ reporter = Reporter.new(formatter)
+
+ formatter.should_receive(:start).with(0,5)
+ RSpec.configuration.start_time = 5
+ reporter.start 0, 10
+ end
+ end
+
context "given one formatter" do
it "passes messages to that formatter" do
formatter = double("formatter")