module Leftovers

To give to matchers before creating a Definition

TODO: find a way for this to remove itself from the chain

Constants

VERSION

Attributes

parallel[RW]
parallel?[RW]
progress[RW]
progress?[RW]
reporter[RW]

Public Instance Methods

collector() click to toggle source
# File lib/leftovers.rb, line 52
def collector
  @collector ||= Leftovers::Collector.new
end
config() click to toggle source
# File lib/leftovers.rb, line 48
def config
  @config ||= Leftovers::MergedConfig.new(load_defaults: true)
end
each_or_self(value) { |value| ... } click to toggle source
# File lib/leftovers.rb, line 148
def each_or_self(value, &block)
  case value
  when nil then nil
  when Array then value.each(&block)
  else yield(value)
  end
end
error(message) click to toggle source
# File lib/leftovers.rb, line 105
def error(message)
  warn(message)
  exit 1
end
exit(status = 0) click to toggle source
# File lib/leftovers.rb, line 126
def exit(status = 0)
  throw :leftovers_exit, status
end
leftovers() click to toggle source
# File lib/leftovers.rb, line 60
def leftovers
  @leftovers ||= begin
    collector.collect
    collector.definitions.reject(&:in_collection?)
  end
end
newline() click to toggle source
# File lib/leftovers.rb, line 118
def newline
  stdout.puts('')
end
print(message) click to toggle source
puts(message) click to toggle source
# File lib/leftovers.rb, line 110
def puts(message)
  stdout.puts("\e[2K#{message}")
end
pwd() click to toggle source
# File lib/leftovers.rb, line 122
def pwd
  @pwd ||= Pathname.new(Dir.pwd + '/')
end
reporter() click to toggle source
# File lib/leftovers.rb, line 56
def reporter
  @reporter ||= Leftovers::Reporter.new
end
reset() click to toggle source
# File lib/leftovers.rb, line 85
def reset # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
  remove_instance_variable(:@config) if defined?(@config)
  remove_instance_variable(:@collector) if defined?(@collector)
  remove_instance_variable(:@reporter) if defined?(@reporter)
  remove_instance_variable(:@leftovers) if defined?(@leftovers)
  remove_instance_variable(:@try_require) if defined?(@try_require)
  remove_instance_variable(:@stdout) if defined?(@stdout)
  remove_instance_variable(:@stderr) if defined?(@stderr)
  remove_instance_variable(:@parallel) if defined?(@parallel)
  remove_instance_variable(:@pwd) if defined?(@pwd)
end
run(stdout: StringIO.new, stderr: StringIO.new) click to toggle source
# File lib/leftovers.rb, line 67
def run(stdout: StringIO.new, stderr: StringIO.new) # rubocop:disable Metrics/MethodLength
  @stdout = stdout
  @stderr = stderr
  return reporter.report_success if leftovers.empty?

  only_test = []
  none = []
  leftovers.sort_by(&:location_s).each do |definition|
    if !definition.test? && definition.in_test_collection?
      only_test << definition
    else
      none << definition
    end
  end

  reporter.report(only_test: only_test, none: none)
end
stderr() click to toggle source
# File lib/leftovers.rb, line 44
def stderr
  @stderr ||= $stderr
end
stdout() click to toggle source
# File lib/leftovers.rb, line 40
def stdout
  @stdout ||= $stdout
end
try_require(requirable, message: nil) click to toggle source
# File lib/leftovers.rb, line 130
def try_require(requirable, message: nil) # rubocop:disable Metrics/MethodLength
  @try_require ||= {}

  @try_require[requirable] = begin
    if @try_require.key?(requirable)
      @try_require[requirable]
    else
      require requirable
      true
    end
  rescue LoadError
    false
  end

  warn message if !@try_require[requirable] && message
  @try_require[requirable]
end
warn(message) click to toggle source
# File lib/leftovers.rb, line 101
def warn(message)
  stderr.puts("\e[2K#{message}")
end