Skip to content

Commit

Permalink
Fix tests with the seed option
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyazub committed Jun 3, 2024
1 parent b4a886b commit c5bf35c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
turbo_tests (2.2.3)
turbo_tests (2.2.4)
parallel_tests (>= 3.3.0, < 5)
rspec (>= 3.10)

Expand Down
25 changes: 16 additions & 9 deletions lib/turbo_tests/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,25 @@ def add(name, outputs)
end

# Borrowed from RSpec::Core::Reporter
# https://github.com/rspec/rspec-core/blob/1eeadce5aa7137ead054783c31ff35cbfe9d07cc/lib/rspec/core/reporter.rb#L206
def report(expected_example_count)
start(expected_example_count)
# https://github.com/rspec/rspec-core/blob/5699fcdc4723087ff6139af55bd155ad9ad61a7b/lib/rspec/core/reporter.rb#L71
def report(example_groups)
start(example_groups)
begin
yield self
ensure
finish
end
end

def start(example_groups)
delegate_to_formatters(:seed, RSpec::Core::Notifications::SeedNotification.new(@seed, @seed_used))
def start(example_groups, time=RSpec::Core::Time.now)
@start = time
@load_time = (@start - @start_time).to_f

report_number_of_tests(example_groups)
expected_example_count = example_groups.flatten(1).count

delegate_to_formatters(:seed, RSpec::Core::Notifications::SeedNotification.new(@seed, @seed_used))
delegate_to_formatters(:start, RSpec::Core::Notifications::StartNotification.new(expected_example_count, @load_time))
end

def report_number_of_tests(groups)
Expand Down Expand Up @@ -119,8 +124,10 @@ def error_outside_of_examples
def finish
end_time = RSpec::Core::Time.now

delegate_to_formatters(:start_dump,
RSpec::Core::Notifications::NullNotification)
@duration = end_time - @start_time
delegate_to_formatters :stop, RSpec::Core::Notifications::ExamplesNotification.new(self)

delegate_to_formatters :start_dump, RSpec::Core::Notifications::NullNotification
delegate_to_formatters(:dump_pending,
RSpec::Core::Notifications::ExamplesNotification.new(
self
Expand All @@ -138,13 +145,13 @@ def finish
@load_time,
@errors_outside_of_examples_count
))
delegate_to_formatters(:close,
RSpec::Core::Notifications::NullNotification)
delegate_to_formatters(:seed,
RSpec::Core::Notifications::SeedNotification.new(
@seed,
@seed_used,
))
ensure
delegate_to_formatters :close, RSpec::Core::Notifications::NullNotification
end

protected
Expand Down
2 changes: 1 addition & 1 deletion lib/turbo_tests/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TurboTests
VERSION = "2.2.3"
VERSION = "2.2.4"
end
7 changes: 4 additions & 3 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
context "errors outside of examples" do
let(:expected_start_of_output) {
%(
Randomized with seed #{seed}
1 processes for 1 specs, ~ 1 specs per process
Randomized with seed #{seed}
An error occurred while loading #{fixture}.
\e[31mFailure/Error: \e[0m\e[1;34m1\e[0m / \e[1;34m0\e[0m\e[0m
\e[31m\e[0m
Expand All @@ -27,7 +28,7 @@

let(:expected_end_of_output) do
"0 examples, 0 failures\n"\
"\n\n"\
"\n"\
"Randomized with seed #{seed}"
end

Expand Down Expand Up @@ -57,7 +58,7 @@
expect(output).to include(part)
end

expect(output).to end_with("3 examples, 0 failures, 3 pending\n\n\nRandomized with seed #{seed}")
expect(output).to end_with("3 examples, 0 failures, 3 pending\n\nRandomized with seed #{seed}")
end
end
end
Expand Down

0 comments on commit c5bf35c

Please sign in to comment.