chop 0.38.7 → 0.38.9

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: 0c453a9613684dc9598f926969f736b6dcf97f2e3ff15103ab1e41f6f73e19d6
4
- data.tar.gz: 70e8130184d8e8a443b7fd8db27e19512963eb288b4db200e98665cfa040345b
3
+ metadata.gz: 33e0405a3677b6e1990ebd590d701b3815c89cbb5a024649b3ac1edaa437b1f9
4
+ data.tar.gz: 7894fbc727c4d526d801b5c7c053345060982389b3c217086de49d739a7f39c7
5
5
  SHA512:
6
- metadata.gz: cdbc3afa528f1608df517ab34eb4d215ea462608377ef4d1cf0b5e073303d961ab37264ecd5aa26789640b9da06f279c95ac0aea7869a87260f8b136af13138f
7
- data.tar.gz: aa9e605301db184c994ad5220a9c8b5ca299fec728088fd7bbc3ebbb6b57cfdf625c66fd387da3024192b2762cd31e2d5aa8f5afef3eb7b154309197dc9f6319
6
+ metadata.gz: d87670a9c0c8d0d85e2373f65598784b5bfe0342992e63cdd2d6ca244cee1fe3436af7fa29f9fef42344c9c94e2d522a2354f3e87770d17568ea8e7809e02c19
7
+ data.tar.gz: d80fdc383bdffc7fcd5d6b2219768ae9b5a5fb647b81fd23c3b28f5c311d257909cc6de5278c3eed3d04dacdc8b3b7e4fe0c2c76f6ce6bb8d824ab551d26ab90
@@ -5,8 +5,8 @@ jobs:
5
5
  strategy:
6
6
  fail-fast: false
7
7
  matrix:
8
- gemfile: [ rails_7.0, rails_7.1, rails_7.2 ]
9
- ruby: [ 3.1, 3.2, 3.3 ]
8
+ gemfile: [ rails_8.1 ]
9
+ ruby: [ "3.3", "3.4", "4.0" ]
10
10
 
11
11
  runs-on: ubuntu-latest
12
12
  env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
data/Appraisals CHANGED
@@ -1,12 +1,4 @@
1
- appraise "rails-7.0" do
2
- gem "rails", "~>7.0.0"
3
- end
4
-
5
- appraise "rails-7.1" do
6
- gem "rails", "~>7.1.0"
7
- end
8
-
9
- appraise "rails-7.2" do
10
- gem "rails", "~>7.2.0"
1
+ appraise "rails-8.1" do
2
+ gem "rails", "~>8.1.0"
11
3
  end
12
4
 
data/CLAUDE.md CHANGED
@@ -20,9 +20,9 @@ Note: RSpec is configured to run only tests marked with `focus: true`. When no f
20
20
  - `bin/console` - Interactive console for experimentation
21
21
 
22
22
  ### Multi-Version Testing
23
- Tests must pass against Rails 7.0, 7.1, and 7.2 on Ruby 3.1, 3.2, and 3.3:
23
+ Tests must pass against Rails 8.1 on Ruby 3.3, 3.4, and 4.0:
24
24
  - `bundle exec appraisal install` - Install gems for all Rails versions
25
- - `bundle exec appraisal rails-7.0 rspec` - Test against specific Rails version
25
+ - `bundle exec appraisal rails-8.1 rspec` - Test against specific Rails version
26
26
  - `bundle exec appraisal rspec` - Test against all Rails versions
27
27
 
28
28
  ### Gem Management
@@ -69,6 +69,20 @@ Diffing works by:
69
69
  3. Comparing against the expected table using `diff!` from Cucumber
70
70
  4. Supporting element-specific extraction logic (e.g., images in table cells)
71
71
 
72
+ Every `diff!`, including `Chop::Form`'s, wraps the read in `synchronize` and
73
+ re-reads until it matches or the timeout expires. Capybara's `synchronize` is not
74
+ re-entrant, so finders inside that block get a single attempt each and their
75
+ errors have to be retriable at the outer level. A block that post-processes
76
+ `actual` should raise `Capybara::ElementNotFound` to request a re-read.
77
+
78
+ When `Chop.atomic_diff` is on, an atomic read first waits for the page to go idle
79
+ (`Diff#wait_for_idle!`), then disables script execution for the duration of the
80
+ read. Idle means no in-flight network and no frame Turbo is actually fetching —
81
+ lazy and disabled frames carry a `src` that is never fetched, so counting them
82
+ would mean the page is never idle. The check has to hold for
83
+ `IDLE_SAMPLES_REQUIRED` consecutive samples, since the gap between a click and
84
+ the request it triggers also looks idle.
85
+
72
86
  ## Testing Patterns
73
87
 
74
88
  - Uses RSpec with `spec_helper.rb` configuring focus filtering
data/README.md CHANGED
@@ -117,6 +117,31 @@ All these methods are implemented in terms of the following low-level methods, u
117
117
  * `#hash_transformation`: performs arbitrary transformations on an array of hashes constructed by assuming a header row. Hash keys are downcased and underscored.
118
118
  * `#transformation`: performs arbitrary transformations on the 2d array of Capybara nodes.
119
119
 
120
+ ### Diffing a `<form>`:
121
+
122
+ Form diffs take a block that post-processes the rows before comparison:
123
+
124
+ ``` ruby
125
+ table.diff! "#ticket_1", as: :form do |actual, root|
126
+ actual.insert 0, ["Owned by", root.all("owners-select option[selected]").map(&:text).join(" ")]
127
+ end
128
+ ```
129
+
130
+ Like every other `#diff!`, the read is retried until it matches or the timeout
131
+ expires, so the block can be handed a form that is still rendering. Raise
132
+ `Capybara::ElementNotFound` to ask for a re-read rather than working with what is
133
+ there:
134
+
135
+ ``` ruby
136
+ index = actual.index { |row| row.first == "Requested by" }
137
+ raise Capybara::ElementNotFound, "no \"Requested by\" row yet" unless index
138
+ ```
139
+
140
+ Reads inside the block should pass `minimum: 0` to Capybara's `#all`. Its default
141
+ of `minimum: 1` waits out the whole timeout before conceding that a collection is
142
+ legitimately empty, and the retry above already covers a collection that has not
143
+ rendered yet.
144
+
120
145
  ### Block methods for `#fill_in!`:
121
146
 
122
147
  TODO: Does this make sense?
data/chop.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency "cucumber"
24
24
  spec.add_dependency "capybara"
25
25
 
26
- spec.add_development_dependency "sqlite3", "~> 1.4"
26
+ spec.add_development_dependency "sqlite3", "~> 2.9", ">= 2.9.6"
27
27
  spec.add_development_dependency "appraisal"
28
28
  spec.add_development_dependency "rake"
29
29
  spec.add_development_dependency "rspec"
@@ -5,6 +5,6 @@ source "https://rubygems.org"
5
5
  gem "byebug"
6
6
  gem "puma", "~>5.0"
7
7
  gem "rack", "~>2.0"
8
- gem "rails", "~>7.0.0"
8
+ gem "rails", "~>8.1.0"
9
9
 
10
10
  gemspec path: "../"
data/lib/chop/diff.rb CHANGED
@@ -202,16 +202,30 @@ module Chop
202
202
  nil
203
203
  end
204
204
 
205
+ # The page has to look quiet for a continuous window before we believe it,
206
+ # since the gap between a click and the fetch it triggers also looks quiet.
207
+ # Widen this on slow or oversubscribed machines, where "quiet" more often
208
+ # means "descheduled" than "finished".
209
+ IDLE_POLL_INTERVAL = 0.05
210
+ IDLE_SAMPLES_REQUIRED = 10
211
+
212
+ # A `src` on a lazy or disabled frame is never fetched, so counting those as
213
+ # pending means the page never goes idle and every atomic diff burns its
214
+ # whole timeout. `busy` covers a lazy frame that has just come into view.
215
+ PENDING_FRAMES_SELECTOR = 'turbo-frame[busy], turbo-frame[src]:not([complete]):not([disabled]):not([loading="lazy"])'
216
+
205
217
  def wait_for_idle!
206
218
  return unless cdp_page
207
219
 
208
220
  start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
221
+ idle_samples = 0
209
222
  loop do
210
223
  break if Process.clock_gettime(Process::CLOCK_MONOTONIC) - start > timeout
211
- pending_frames = session.evaluate_script("document.querySelectorAll('turbo-frame[src]:not([complete]), turbo-frame[busy]').length")
224
+ pending_frames = session.evaluate_script("document.querySelectorAll(#{PENDING_FRAMES_SELECTOR.inspect}).length")
212
225
  pending_network = session.driver.browser.network.pending_connections
213
- break if pending_frames == 0 && pending_network == 0
214
- sleep 0.05
226
+ idle_samples = (pending_frames == 0 && pending_network == 0) ? idle_samples + 1 : 0
227
+ break if idle_samples >= IDLE_SAMPLES_REQUIRED
228
+ sleep IDLE_POLL_INTERVAL
215
229
  end
216
230
  end
217
231
 
data/lib/chop/form.rb CHANGED
@@ -7,7 +7,21 @@ module Chop
7
7
  new(table, session, path).fill_in!
8
8
  end
9
9
 
10
- def self.diff! selector, table, session: Capybara.current_session, &block
10
+ # Capybara's #synchronize is not re-entrant, so the finds below get a single
11
+ # attempt each and have to retry out here instead — hence ElementNotFound in
12
+ # the error list. A block that post-processes `actual` should raise
13
+ # Capybara::ElementNotFound to ask for a re-read of a half-rendered form.
14
+ def self.diff! selector, table, session: Capybara.current_session, timeout: nil, &block
15
+ errors = session.driver.invalid_element_errors + [
16
+ Cucumber::MultilineArgument::DataTable::Different,
17
+ Capybara::ElementNotFound,
18
+ ]
19
+ session.document.synchronize timeout || Capybara.default_max_wait_time, errors: errors do
20
+ diff_once! selector, table, session: session, &block
21
+ end
22
+ end
23
+
24
+ def self.diff_once! selector, table, session:, &block
11
25
  root = begin
12
26
  if selector.is_a?(Capybara::Node::Element)
13
27
  selector
@@ -28,7 +42,7 @@ module Chop
28
42
  block.call(actual, root) if block_given?
29
43
  table.diff! actual, surplus_row: false, misplaced_col: false
30
44
  end
31
-
45
+ private_class_method :diff_once!
32
46
 
33
47
  def fill_in!
34
48
  table.rows_hash.each do |label, value|
@@ -48,7 +62,7 @@ module Chop
48
62
  @locator = locator.to_s
49
63
 
50
64
  @session.document.synchronize do
51
- @all_fields = @session.all(@css_selector, wait: false)
65
+ @all_fields = candidate_fields
52
66
 
53
67
  find_by_direct_attributes ||
54
68
  find_by_aria_label ||
@@ -60,6 +74,33 @@ module Chop
60
74
 
61
75
  private
62
76
 
77
+ def candidate_fields
78
+ narrowed = @session.driver.wait? ? narrowed_fields : []
79
+ narrowed.any? ? narrowed : @session.all(@css_selector, wait: false)
80
+ end
81
+
82
+ # Must stay a superset of what the find_by_* methods match: they decide, this only spares them a round trip per field.
83
+ def narrowed_fields
84
+ scope = @session.current_scope
85
+ root = scope if scope.is_a?(Capybara::Node::Element)
86
+
87
+ fields = @session.evaluate_script(<<~'JS', @css_selector, @locator, root)
88
+ ((css, locator, root) => {
89
+ const scope = root || document
90
+ const squash = (text) => String(text).replace(/[\s\u0085\u180e\u200b\u200e\u200f]/g, "")
91
+ const target = squash(locator)
92
+ const labels = [...scope.querySelectorAll("label")].filter((label) => squash(label.textContent).includes(target))
93
+ const labelledIds = new Set(labels.map((label) => label.getAttribute("for")))
94
+ return [...scope.querySelectorAll(css)].filter((field) =>
95
+ ["id", "name", "placeholder", "aria-label"].some((name) => field[name] === locator || field.getAttribute(name) === locator)
96
+ || labelledIds.has(field.id) || labelledIds.has(field.getAttribute("id"))
97
+ || labels.includes(field.closest("label")))
98
+ })(arguments[0], arguments[1], arguments[2])
99
+ JS
100
+
101
+ @session.config.ignore_hidden_elements ? fields.select(&:visible?) : fields
102
+ end
103
+
63
104
  def find_by_direct_attributes
64
105
  @all_fields.find do |field|
65
106
  field[:id] == @locator ||
data/lib/chop/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Chop
2
- VERSION = "0.38.7"
2
+ VERSION = "0.38.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.38.7
4
+ version: 0.38.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-04-03 00:00:00.000000000 Z
11
+ date: 2026-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -58,14 +58,20 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.4'
61
+ version: '2.9'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.9.6
62
65
  type: :development
63
66
  prerelease: false
64
67
  version_requirements: !ruby/object:Gem::Requirement
65
68
  requirements:
66
69
  - - "~>"
67
70
  - !ruby/object:Gem::Version
68
- version: '1.4'
71
+ version: '2.9'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.9.6
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: appraisal
71
77
  requirement: !ruby/object:Gem::Requirement
@@ -156,9 +162,7 @@ files:
156
162
  - bin/setup
157
163
  - chop.gemspec
158
164
  - gemfiles/.bundle/config
159
- - gemfiles/rails_7.0.gemfile
160
- - gemfiles/rails_7.1.gemfile
161
- - gemfiles/rails_7.2.gemfile
165
+ - gemfiles/rails_8.1.gemfile
162
166
  - lib/chop.rb
163
167
  - lib/chop/config.rb
164
168
  - lib/chop/create.rb
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "byebug"
6
- gem "puma", "~>5.0"
7
- gem "rack", "~>2.0"
8
- gem "rails", "~>7.1.0"
9
-
10
- gemspec path: "../"
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "byebug"
6
- gem "puma", "~>5.0"
7
- gem "rack", "~>2.0"
8
- gem "rails", "~>7.2.0"
9
-
10
- gemspec path: "../"