Sha256: 4bb5f5b42e462db2c47fe3c77dd991996b6858c011970db95ba206de03071b9b

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

require 'forwardable'

require File.expand_path('../warnings_spy/filesystem', __FILE__)
require File.expand_path('../warnings_spy/reader', __FILE__)
require File.expand_path('../warnings_spy/partitioner', __FILE__)
require File.expand_path('../warnings_spy/reporter', __FILE__)

class WarningsSpy
  extend Forwardable

  def initialize(project_name)
    filesystem = Filesystem.new
    @warnings_file = filesystem.warnings_file
    @reader = Reader.new(filesystem)
    @partitioner = Partitioner.new(reader, filesystem)
    @reporter = Reporter.new(partitioner, filesystem, project_name)
  end

  def capture_warnings
    $stderr.reopen(warnings_file.path)
  end

  def report_warnings_at_exit
    at_exit do
      printing_exceptions do
        report_and_exit
      end
    end
  end

  protected

  attr_reader :warnings_file, :reader, :partitioner, :reporter

  private

  def_delegators :partitioner, :relevant_warning_groups,
    :irrelevant_warning_groups

  def report_and_exit
    reader.read
    partitioner.partition
    reporter.report
    #fail_build_if_there_are_any_warnings
  end

  def fail_build_if_there_are_any_warnings
    if relevant_warning_groups.any?
      exit(1)
    end
  end

  def printing_exceptions
    begin
      yield
    rescue => error
      puts "\n--- ERROR IN AT_EXIT --------------------------------"
      puts "#{error.class}: #{error.message}"
      puts error.backtrace.join("\n")
      puts "-----------------------------------------------------"
      raise error
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/shoulda-matchers-2.8.0/spec/warnings_spy.rb
shoulda-matchers-2.8.0 spec/warnings_spy.rb
shoulda-matchers-2.8.0.rc2 spec/warnings_spy.rb
shoulda-matchers-2.8.0.rc1 spec/warnings_spy.rb
shoulda-matchers-2.7.0 spec/warnings_spy.rb
shoulda-matchers-2.6.2 spec/warnings_spy.rb