Sha256: 96ffa604ffad646f23f3805225b966ed99799874075f340d1ed8a5df10af3dd9

Contents?: true

Size: 1.48 KB

Versions: 32

Compression:

Stored size: 1.48 KB

Contents

module ExcelHelpers
  class ExcelMatcher
    require 'roo'

    def initialize(fixture_path)
      @fixture_path = fixture_path
      @errors = []
    end

    def matches?(actual_path)
      match_excel(actual_path)

      @errors.empty?
    end

    def failure_message
      "Following cells differ from expected: #{error_messages}"
    end

    private

    def error_messages
      messages = []
      @errors.each do |error|
        messages << "#{error[:cell]} (expect: #{error[:fixture_value]} was: #{error[:actual_value]})"
      end

      messages.join(', ')
    end

    def match_excel actual_path
      fixture = Roo::Spreadsheet.open(@fixture_path)
      fixture.default_sheet = fixture.sheets.first

      actual = Roo::Spreadsheet.open(actual_path)
      actual.default_sheet = actual.sheets.first

      match_sheet(actual, fixture)
    end

    def match_sheet actual, fixture
      rows = fixture.first_row..fixture.last_row
      columns = fixture.first_column..fixture.last_column
      for row in rows
        for column in columns
          fixture_value = fixture.cell(row, column)
          actual_value = actual.cell(row, column)
          if fixture_value != actual_value
            @errors << {
              cell: "#{Roo::Base.number_to_letter(column)}#{row}",
              fixture_value: fixture_value,
              actual_value: actual_value
            }
          end
        end
      end
    end
  end

  def match_excel(fixture_path)
    ExcelMatcher.new(fixture_path)
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
releaf-1.1.22 spec/support/excel_helpers.rb
releaf-1.1.21 spec/support/excel_helpers.rb
releaf-1.1.20 spec/support/excel_helpers.rb
releaf-1.1.19 spec/support/excel_helpers.rb
releaf-1.1.18 spec/support/excel_helpers.rb
releaf-1.1.17 spec/support/excel_helpers.rb
releaf-1.1.16 spec/support/excel_helpers.rb
releaf-1.1.15 spec/support/excel_helpers.rb
releaf-1.1.14 spec/support/excel_helpers.rb
releaf-1.1.13 spec/support/excel_helpers.rb
releaf-1.1.12 spec/support/excel_helpers.rb
releaf-1.1.11 spec/support/excel_helpers.rb
releaf-1.1.10 spec/support/excel_helpers.rb
releaf-1.1.9 spec/support/excel_helpers.rb
releaf-1.1.8 spec/support/excel_helpers.rb
releaf-1.1.7 spec/support/excel_helpers.rb
releaf-1.1.6 spec/support/excel_helpers.rb
releaf-1.1.5 spec/support/excel_helpers.rb
releaf-1.1.4 spec/support/excel_helpers.rb
releaf-1.1.3 spec/support/excel_helpers.rb