Skip to content

Commit

Permalink
Remove compatibility with RSpec 2 (#908)
Browse files Browse the repository at this point in the history
RSpec 3 was released 9 years ago. Most people will have upgraded by now 馃槄
  • Loading branch information
bquorning committed May 25, 2023
1 parent 163f53c commit fed72e4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@

### Breaking Changes

- Drop support for RSpec 2.

### Added

### Fixed
Expand Down
18 changes: 5 additions & 13 deletions lib/parallel_tests/rspec/failures_logger.rb
Expand Up @@ -3,22 +3,14 @@
require 'parallel_tests/rspec/runner'

class ParallelTests::RSpec::FailuresLogger < ParallelTests::RSpec::LoggerBase
if RSPEC_2
def dump_failures(*args); end
else
RSpec::Core::Formatters.register self, :dump_summary
end
RSpec::Core::Formatters.register(self, :dump_summary)

def dump_summary(*args)
lock_output do
if RSPEC_2
dump_commands_to_rerun_failed_examples
else
notification = args.first
unless notification.failed_examples.empty?
colorizer = ::RSpec::Core::Formatters::ConsoleCodes
output.puts notification.colorized_rerun_commands(colorizer)
end
notification = args.first
unless notification.failed_examples.empty?
colorizer = ::RSpec::Core::Formatters::ConsoleCodes
output.puts notification.colorized_rerun_commands(colorizer)
end
end
@output.flush
Expand Down
2 changes: 0 additions & 2 deletions lib/parallel_tests/rspec/logger_base.rb
Expand Up @@ -7,8 +7,6 @@ module RSpec
require 'rspec/core/formatters/base_text_formatter'

class ParallelTests::RSpec::LoggerBase < RSpec::Core::Formatters::BaseTextFormatter
RSPEC_2 = RSpec::Core::Version::STRING.start_with?('2')

def initialize(*args)
super

Expand Down
5 changes: 2 additions & 3 deletions lib/parallel_tests/rspec/runtime_logger.rb
Expand Up @@ -9,7 +9,7 @@ def initialize(*args)
@group_nesting = 0
end

RSpec::Core::Formatters.register self, :example_group_started, :example_group_finished, :start_dump unless RSPEC_2
RSpec::Core::Formatters.register(self, :example_group_started, :example_group_finished, :start_dump)

def example_group_started(example_group)
@time = ParallelTests.now if @group_nesting == 0
Expand All @@ -20,8 +20,7 @@ def example_group_started(example_group)
def example_group_finished(notification)
@group_nesting -= 1
if @group_nesting == 0
path = (RSPEC_2 ? notification.file_path : notification.group.file_path)
@example_times[path] += ParallelTests.now - @time
@example_times[notification.group.file_path] += ParallelTests.now - @time
end
super if defined?(super)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/parallel_tests/rspec/summary_logger.rb
Expand Up @@ -2,7 +2,7 @@
require 'parallel_tests/rspec/failures_logger'

class ParallelTests::RSpec::SummaryLogger < ParallelTests::RSpec::LoggerBase
RSpec::Core::Formatters.register self, :dump_failures unless RSPEC_2
RSpec::Core::Formatters.register(self, :dump_failures)

def dump_failures(*args)
lock_output { super }
Expand Down
2 changes: 1 addition & 1 deletion spec/parallel_tests/rspec/runtime_logger_spec.rb
Expand Up @@ -19,7 +19,7 @@ def log_for_a_file(_options = {})
end

example = double(file_path: "#{Dir.pwd}/spec/foo.rb")
example = double(group: example) unless ParallelTests::RSpec::RuntimeLogger::RSPEC_2
example = double(group: example)

logger.example_group_started example
logger.example_group_finished example
Expand Down

0 comments on commit fed72e4

Please sign in to comment.