Class: RSpec::XlsxMatchers::Cells

Inherits:
BaseSheet
  • Object
show all
Includes:
InRow
Defined in:
lib/rspec/xlsx_matchers/cells.rb

Overview

have_excel_cells

Constant Summary collapse

EXPECTED =
"Expected"
RECEIVED =
"Received"

Instance Attribute Summary collapse

Attributes included from InRow

#row_index

Attributes inherited from BaseSheet

#sheet, #sheet_name, #subject

Instance Method Summary collapse

Methods included from InRow

#in_row

Methods inherited from BaseSheet

#in_sheet, #matches?

Methods included from Utils

#force_array, #map_output

Constructor Details

#initialize(expected_cells) ⇒ Cells

Returns a new instance of Cells.



13
14
15
16
17
18
# File 'lib/rspec/xlsx_matchers/cells.rb', line 13

def initialize(expected_cells)
  super()
  @expected_cells = force_array(expected_cells)
  @actual_cells = []
  @mismatch_indexes = []
end

Instance Attribute Details

#actual_cellsObject (readonly)

Returns the value of attribute actual_cells.



8
9
10
# File 'lib/rspec/xlsx_matchers/cells.rb', line 8

def actual_cells
  @actual_cells
end

#expected_cellsObject (readonly)

Returns the value of attribute expected_cells.



8
9
10
# File 'lib/rspec/xlsx_matchers/cells.rb', line 8

def expected_cells
  @expected_cells
end

#mismatch_indexesObject (readonly)

Returns the value of attribute mismatch_indexes.



8
9
10
# File 'lib/rspec/xlsx_matchers/cells.rb', line 8

def mismatch_indexes
  @mismatch_indexes
end

Instance Method Details

#failure_messageObject

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rspec/xlsx_matchers/cells.rb', line 20

def failure_message # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  return sheet_failure_message if sheet.nil?
  return row_not_found_message if row.nil?

  message = failure_message_header(String.new("Rows did not match : \n"))
  # Cells content
  expected_cells.each_with_index do |expected_cell, idx|
    sizeof_actual_cell = actual_cells[idx].to_s.size
    sizeof_expected_cell = expected_cell.to_s.size
    message << " #{idx}"
    message << (" " * (4 - idx.to_s.size))
    message << "| #{actual_cells[idx]}"
    message << (" " * (biggest_actual_cell_size - sizeof_actual_cell))
    message << " | #{expected_cell}"
    message << (" " * (biggest_expected_cell_size - sizeof_expected_cell))
    message << " | #{mismatch_indexes.include?(idx) ? "<----- Mismatch" : ""}"
    message << "\n"
  end
  message
end