match_table 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77cc25bced0a709998c9d0f308811a3c0c339838082172d2c48e64191bbd72b7
4
- data.tar.gz: 69b3cb5768b9c6c1a0791b3fec61ce6bb2b18d3158990f713902e5d15df07ca5
3
+ metadata.gz: 318e51a75753d999304e5a8c93a9eee0e71c1ed9eaa08ee804dfffa9bba74c02
4
+ data.tar.gz: 34480da0ff98a9aa86b728c7b5cd458cd8a8d7f74d5770036f625410dc926010
5
5
  SHA512:
6
- metadata.gz: ead9964e2f6d2338ec86963d66a30cb0d3bf0a343bf0a0cbfa3625222b76903c73afc9aa943e45a7d6b2f9eab2827099419e36fa809263c49f6d31be5e9521e2
7
- data.tar.gz: 853b507440493137c1df8e7d770b6fde5cd72a11f3ca71b2b215bb619d28ecbe2f4bafd9269a209c7f2637475d281f8f1c20d1cb106f3f9a4a56072084a42d2b
6
+ metadata.gz: 75606e33fd7e0a64726484d93259c6753b8655bbe69e8a7f869ea055a8e095ce1238d7c886d6792ed71c360925975f7d3a8fc6e6fb048a58fef7d6b9d20ac769
7
+ data.tar.gz: e3f7ce2500136ed5b189504b079c3beb34ad119f81fbc36c65a206a369a7e75d6e3104d45bd7be53b129bc86ceadf446c51e9b04c442b63e67d40838f161e251
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.3.0] - 2026-01-16
4
+
5
+ - Match on entire header instead of prefix (#3)
6
+
7
+ ## [1.2.0] - 2025-11-18
8
+
9
+ - Rework hidden header support (#2)
10
+ - Fix an issue where match_table could eat failures (#2)
11
+
12
+ ## [1.1.0] - 2025-09-29
13
+
14
+ - Include hidden headers if they have a child with data-role (#1)
15
+
3
16
  ## [1.0.0] - 2025-04-15
4
17
 
5
18
  - Initial release
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
4
5
  require "standard/rake"
5
6
 
6
- task default: :standard
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: [:spec, :standard]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MatchTable
4
- VERSION = "1.1.0"
4
+ VERSION = "1.3.0"
5
5
  end
data/lib/match_table.rb CHANGED
@@ -24,15 +24,15 @@ RSpec::Matchers.define :match_table do |table|
24
24
 
25
25
  raise ArgumentError, "all rows must have the same headers" unless same_headers
26
26
 
27
- begin
28
- # We'll rerun this block until our expectations are met or we time out.
29
- synchronize do
30
- @failures = []
27
+ # We'll rerun this block until our expectations are met or we time out.
28
+ synchronize do
29
+ @failures = []
30
+ begin
31
31
  find_elements_on_page
32
32
 
33
33
  header_positions =
34
34
  expected_headers.each_with_object({}) do |header, hash|
35
- position = @actual_headers.find_index { |actual_header| actual_header.start_with?(header) }
35
+ position = @actual_headers.find_index { |actual_header| actual_header == header }
36
36
  unless position.nil?
37
37
  hash[header] = position
38
38
  end
@@ -42,27 +42,30 @@ RSpec::Matchers.define :match_table do |table|
42
42
  @actual_rows.each do |actual_row|
43
43
  matched_rows << match_row(header_positions:, actual_row:)
44
44
  end
45
+ rescue Capybara::ExpectationNotMet => e
46
+ raise "Internal match_table error: #{e.message}"
47
+ end
45
48
 
46
- @actual = matched_rows
47
- @expected_as_array = Array(@expected_rows)
49
+ @actual = matched_rows
50
+ @expected_as_array = Array(@expected_rows)
48
51
 
49
- # Grab the failures from these expectations so we can use their failure messages
50
- RSpec::Support.with_failure_notifier(append_to_failures_array_notifier) do
51
- case @mode
52
- when :exact
53
- expect(actual).to eq(expected_as_array)
54
- when :include
55
- expect(actual).to include(*expected_as_array)
56
- end
52
+ # Grab the failures from these expectations so we can use their failure messages
53
+ RSpec::Support.with_failure_notifier(append_to_failures_array_notifier) do
54
+ case @mode
55
+ when :exact
56
+ expect(actual).to eq(expected_as_array)
57
+ when :include
58
+ expect(actual).to include(*expected_as_array)
57
59
  end
58
-
59
- raise Capybara::ExpectationNotMet unless @failures.empty?
60
60
  end
61
- rescue Capybara::ExpectationNotMet
62
- false
61
+
62
+ # raise to signal to synchronize that we need to retry
63
+ raise Capybara::ExpectationNotMet unless @failures.empty?
63
64
  end
64
65
 
65
66
  @failures.empty?
67
+ rescue Capybara::ExpectationNotMet
68
+ false
66
69
  end
67
70
 
68
71
  # Match the table exactly with the provided rows in order.
@@ -108,17 +111,27 @@ RSpec::Matchers.define :match_table do |table|
108
111
  table = find_table(@table)
109
112
 
110
113
  @actual_headers =
111
- table.find("thead").all("th").map(&:text).compact_blank
114
+ table.find("thead").all("th", visible: :all).map do |element|
115
+ text = element.text
116
+ if text.nil? || text.empty?
117
+ text = element.first("[data-role]", visible: :all, minimum: 0)&.text(:all) || ""
118
+ end
112
119
 
113
- @actual_headers +=
114
- table.find("thead").all("th", visible: :hidden).map do |element|
115
- element.first("[data-role]").text(:all)
116
- end.compact_blank
120
+ normalize_header_text(text)
121
+ end
117
122
 
118
123
  @actual_rows = []
119
124
 
120
- rows = table.find("tbody:not(.contents)").all("tr[data-table-target='row']:not([data-accordion-content] table tr)").presence ||
121
- table.find("tbody:not(.contents)").all("tr[data-table-target='row']")
125
+ tbody = table.find("tbody:not(.contents)")
126
+ rows = tbody.all("tr[data-table-target='row']")
127
+
128
+ # Filter out rows that are inside accordion content of table rows
129
+ # Only reject rows that are inside a tr[data-accordion-content] that is within this specific table
130
+ rows = rows.reject do |row|
131
+ row.ancestor("tr[data-accordion-content]", minimum: 0)
132
+ rescue Capybara::ElementNotFound
133
+ false
134
+ end
122
135
 
123
136
  rows.each do |row|
124
137
  cells = row.all("td")
@@ -132,6 +145,15 @@ RSpec::Matchers.define :match_table do |table|
132
145
  end
133
146
  end
134
147
 
148
+ def normalize_header_text(text)
149
+ return text if text.nil? || text.empty?
150
+
151
+ text
152
+ .gsub(/arrow_drop_(up|down)/, "")
153
+ .gsub(/\s+/, " ")
154
+ .strip
155
+ end
156
+
135
157
  def append_to_failures_array_notifier
136
158
  lambda { |failure, _opts| @failures << failure }
137
159
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: match_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Schlesinger
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-09-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rspec-expectations
@@ -60,7 +59,6 @@ metadata:
60
59
  allowed_push_host: https://rubygems.org
61
60
  homepage_uri: https://github.com/detaso/match_table
62
61
  source_code_uri: https://github.com/detaso/match_table
63
- post_install_message:
64
62
  rdoc_options: []
65
63
  require_paths:
66
64
  - lib
@@ -75,8 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
73
  - !ruby/object:Gem::Version
76
74
  version: '0'
77
75
  requirements: []
78
- rubygems_version: 3.5.22
79
- signing_key:
76
+ rubygems_version: 3.7.2
80
77
  specification_version: 4
81
78
  summary: Adds a `match_table` matcher for your Capybara system specs.
82
79
  test_files: []