class RSpec::Core::Bisect::ExampleMinimizer

@private Contains the core bisect logic. Searches for examples we can ignore by repeatedly running different subsets of the suite.

Constants

ExampleRange

@private Convenience class for describing a subset of the candidate examples

Attributes

Public Class Methods

# File rspec-core/lib/rspec/core/bisect/example_minimizer.rb, line 13
def initialize(shell_command, runner, notifier)
  @shell_command = shell_command
  @runner        = runner
  @notifier      = notifier
end

Public Instance Methods

# File rspec-core/lib/rspec/core/bisect/example_minimizer.rb, line 33
def bisect(candidate_ids)
  notify(:bisect_dependency_check_started)
  if get_expected_failures_for?([])
    notify(:bisect_dependency_check_failed)
    self.remaining_ids = []
    return
  end
  notify(:bisect_dependency_check_passed)

  bisect_over(candidate_ids)
end
# File rspec-core/lib/rspec/core/bisect/example_minimizer.rb, line 45
def bisect_over(candidate_ids)
  return if candidate_ids.one?

  notify(
    :bisect_round_started,
    :candidate_range => example_range(candidate_ids),
    :candidates_count => candidate_ids.size
  )

  slice_size = (candidate_ids.length / 2.0).ceil
  lhs, rhs = candidate_ids.each_slice(slice_size).to_a

  ids_to_ignore, duration = track_duration do
    [lhs, rhs].find do |ids|
      get_expected_failures_for?(remaining_ids - ids)
    end
  end

  if ids_to_ignore
    self.remaining_ids -= ids_to_ignore
    notify(
      :bisect_round_ignoring_ids,
      :ids_to_ignore => ids_to_ignore,
      :ignore_range => example_range(ids_to_ignore),
      :remaining_ids => remaining_ids,
      :duration => duration
    )
    bisect_over(candidate_ids - ids_to_ignore)
  else
    notify(
      :bisect_round_detected_multiple_culprits,
      :duration => duration
    )
    bisect_over(lhs)
    bisect_over(rhs)
  end
end
# File rspec-core/lib/rspec/core/bisect/example_minimizer.rb, line 83
def currently_needed_ids
  remaining_ids + failed_example_ids
end
# File rspec-core/lib/rspec/core/bisect/example_minimizer.rb, line 19
def find_minimal_repro
  prep

  _, duration = track_duration do
    bisect(non_failing_example_ids)
  end

  notify(:bisect_complete, :duration => duration,
                           :original_non_failing_count => non_failing_example_ids.size,
                           :remaining_count => remaining_ids.size)

  remaining_ids + failed_example_ids
end
# File rspec-core/lib/rspec/core/bisect/example_minimizer.rb, line 87
def repro_command_for_currently_needed_ids
  return shell_command.repro_command_from(currently_needed_ids) if remaining_ids
  "(Not yet enough information to provide any repro command)"
end