From 4e05da24c1260c098a0bf63a412e5622600a88bc Mon Sep 17 00:00:00 2001 From: Christophe Bliard Date: Tue, 14 May 2024 15:31:12 +0200 Subject: [PATCH] Table helper can have first line being a comment --- spec/support/table_helpers/table_parser.rb | 15 ++++++--------- .../table_helpers/table_parser_spec.rb | 1 + 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/spec/support/table_helpers/table_parser.rb b/spec/support/table_helpers/table_parser.rb index 80466f3e45d..4ac10ceee87 100644 --- a/spec/support/table_helpers/table_parser.rb +++ b/spec/support/table_helpers/table_parser.rb @@ -31,14 +31,12 @@ module TableHelpers class TableParser def parse(representation) - headers, *rows = representation.split("\n") - headers = split(headers) - rows = rows.filter_map { |row| parse_row(row, headers) } - work_packages_data = rows.map.with_index do |row, index| + headers, *rows = representation.split("\n").filter_map { |line| split_line_into_cells(line) } + work_packages_data = rows.map.with_index do |cells, index| { attributes: {}, index:, - row: + row: headers.zip(cells).to_h } end headers.each do |header| @@ -50,13 +48,12 @@ module TableHelpers private - def parse_row(row, headers) - case row + def split_line_into_cells(line) + case line when "", /^\s*#/ # noop else - values = split(row) - headers.zip(values).to_h + split(line) end end diff --git a/spec/support_spec/table_helpers/table_parser_spec.rb b/spec/support_spec/table_helpers/table_parser_spec.rb index 12d0b34e2f1..843d500cd13 100644 --- a/spec/support_spec/table_helpers/table_parser_spec.rb +++ b/spec/support_spec/table_helpers/table_parser_spec.rb @@ -53,6 +53,7 @@ RSpec.describe TableHelpers::TableParser do it "ignores comments and empty lines" do table = <<~TABLE + # this comment is ignored | subject | # this comment and the following empty line are ignored