Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Remove sleeps from formatter specs #1288

Merged
merged 1 commit into from
Feb 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/rspec/core/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def description
# running this example.
attr_reader :example_group_instance

# @attr_accessor
# @private
attr_accessor :clock

# Creates a new instance of Example.
# @param example_group_class the subclass of ExampleGroup in which this Example is declared
# @param description the String passed to the `it` method (or alias)
Expand All @@ -81,6 +85,7 @@ def initialize(example_group_class, description, metadata, example_block=nil)
@metadata = @example_group_class.metadata.for_example(description, metadata)
@example_group_instance = @exception = nil
@pending_declared_in_example = false
@clock = RSpec::Core::Time
end

# @deprecated access options via metadata instead
Expand Down Expand Up @@ -248,7 +253,7 @@ def with_around_each_hooks(&block)

def start(reporter)
reporter.example_started(self)
record :started_at => RSpec::Core::Time.now
record :started_at => clock.now
end

def finish(reporter)
Expand All @@ -272,7 +277,7 @@ def finish(reporter)
end

def record_finished(status, results={})
finished_at = RSpec::Core::Time.now
finished_at = clock.now
record results.merge(:status => status, :finished_at => finished_at, :run_time => (finished_at - execution_result[:started_at]).to_f)
end

Expand Down
20 changes: 11 additions & 9 deletions spec/rspec/core/formatters/base_text_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,11 @@ def run_all_and_dump_pending

before do
group = RSpec::Core::ExampleGroup.describe("group") do
# Use a sleep so there is some measurable time, to ensure
# the reported percent is 100%, not 0%.
example("example") { sleep 0.001 }
example_line_number = __LINE__ - 1
example("example") do |example|
# make it look slow without actually taking up precious time
example.clock = class_double(RSpec::Core::Time, :now => RSpec::Core::Time.now + 0.5)
end
example_line_number = __LINE__ - 4
end
group.run(reporter)

Expand Down Expand Up @@ -297,9 +298,10 @@ def run_all_and_dump_pending
describe "#dump_profile_slowest_example_groups", :slow do
let(:group) do
RSpec::Core::ExampleGroup.describe("slow group") do
# Use a sleep so there is some measurable time, to ensure
# the reported percent is 100%, not 0%.
example("example") { sleep 0.01 }
example("example") do |example|
# make it look slow without actually taking up precious time
example.clock = class_double(RSpec::Core::Time, :now => RSpec::Core::Time.now + 0.5)
end
end
end

Expand All @@ -320,8 +322,8 @@ def run_all_and_dump_pending
context "with multiple example groups" do
before do
group2 = RSpec::Core::ExampleGroup.describe("fast group") do
example("example 1") { sleep 0.004 }
example("example 2") { sleep 0.007 }
example("example 1") { }
example("example 2") { }
end
group2.run(reporter)

Expand Down
15 changes: 7 additions & 8 deletions spec/rspec/core/formatters/json_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@

before do
group = RSpec::Core::ExampleGroup.describe("group") do
# Use a sleep so there is some measurable time, to ensure
# the reported percent is 100%, not 0%.
example("example") { sleep 0.001 }
example("example") { }
end
group.run(reporter)

Expand All @@ -142,9 +140,10 @@
describe "#dump_profile_slowest_example_groups", :slow do
let(:group) do
RSpec::Core::ExampleGroup.describe("slow group") do
# Use a sleep so there is some measurable time, to ensure
# the reported percent is 100%, not 0%.
example("example") { sleep 0.01 }
example("example") do |example|
# make it look slow without actually taking up precious time
example.clock = class_double(RSpec::Core::Time, :now => RSpec::Core::Time.now + 0.5)
end
end
end

Expand All @@ -165,8 +164,8 @@
context "with multiple example groups", :slow do
before do
group2 = RSpec::Core::ExampleGroup.describe("fast group") do
example("example 1") { sleep 0.004 }
example("example 2") { sleep 0.007 }
example("example 1") { }
example("example 2") { }
end
group2.run(reporter)

Expand Down