Sha256: 95e26d17809f5312bd2e81296fceec1aeb7182508d8179930fe36dae3084b296

Contents?: true

Size: 950 Bytes

Versions: 13

Compression:

Stored size: 950 Bytes

Contents

class WarningsSpy
  class Reader
    attr_reader :warning_groups

    def initialize(filesystem)
      @warnings_file = filesystem.warnings_file

      @current_group = []
      @warning_groups = []
    end

    def read
      warnings_file.rewind

      warnings_file.each_line do |line|
        process_line(line)
      end

      add_group(current_group)
    end

    protected

    attr_reader :warnings_file, :current_group

    private

    def process_line(line)
      if start_of_group?(line)
        add_group(current_group)
        @current_group = []
      end

      current_group << line
    end

    def start_of_group?(line)
      line =~ /^\S/
    end

    def add_group(group)
      unless group.empty? || group_already_added?(group)
        warning_groups << group
      end
    end

    def group_already_added?(group_to_be_added)
      warning_groups.any? do |group|
        group == group_to_be_added
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
shoulda-matchers-3.1.3 spec/warnings_spy/reader.rb
shoulda-matchers-4.0.0.rc1 spec/warnings_spy/reader.rb
shoulda-3.6.0 test/warnings_spy/reader.rb
shoulda-matchers-3.1.2 spec/warnings_spy/reader.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/shoulda-matchers-2.8.0/spec/warnings_spy/reader.rb
shoulda-matchers-3.1.1 spec/warnings_spy/reader.rb
shoulda-matchers-3.1.0 spec/warnings_spy/reader.rb
shoulda-matchers-3.0.1 spec/warnings_spy/reader.rb
shoulda-matchers-3.0.0 spec/warnings_spy/reader.rb
shoulda-matchers-3.0.0.rc1 spec/warnings_spy/reader.rb
shoulda-matchers-2.8.0 spec/warnings_spy/reader.rb
shoulda-matchers-2.8.0.rc2 spec/warnings_spy/reader.rb
shoulda-matchers-2.8.0.rc1 spec/warnings_spy/reader.rb