Class: RSpec::XlsxMatchers::Sheets

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/rspec/xlsx_matchers/sheets.rb

Overview

have_excel_sheets

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#force_array, #map_output

Constructor Details

#initialize(expected_sheet_names) ⇒ Sheets

Returns a new instance of Sheets.



10
11
12
13
# File 'lib/rspec/xlsx_matchers/sheets.rb', line 10

def initialize(expected_sheet_names)
  @expected_sheet_names = force_array expected_sheet_names
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#expected_sheet_namesObject (readonly)

Returns the value of attribute expected_sheet_names.



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

def expected_sheet_names
  @expected_sheet_names
end

Instance Method Details

#failure_messageObject



27
28
29
# File 'lib/rspec/xlsx_matchers/sheets.rb', line 27

def failure_message
  "Xlsx file sheets not found: #{errors.map { |s| "'#{s}'" }.join(",")}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rspec/xlsx_matchers/sheets.rb', line 15

def matches?(subject)
  if subject.is_a?(String) || subject.is_a?(File)
    match_string(subject)
  elsif defined?(Roo::Excelx) && subject.is_a?(Roo::Excelx)
    match_roo_excelx(subject)
  elsif defined?(Axlsx)
    matches_axlsx?(subject)
  else
    invalid_file
  end
end