capybara-validate_html5 2.0.0 → 2.1.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: 0f32ed1925ec14c9311dd217c9b7d0639d79fef0040d5b6f21393f5553267ec3
4
- data.tar.gz: a39dab6f833867d06d5cac1260693588885788f3de193234b1789a71121d737e
3
+ metadata.gz: f2b1d78fdef99821bc035edd33ace215061c0393e561ecf3033655a48d1e1f39
4
+ data.tar.gz: e30b30b5ec5522421a9f4a3fa340470a88437126ef259da24a4878ff1e3673d9
5
5
  SHA512:
6
- metadata.gz: cf51d9e611941e92ab1c5aeca7b9d70e660e39a72ff07d95d8fe8389160095141fa8a67d6ef5493d455216c539e5745dbf851d3558fe47abdf32d96fa4f7230f
7
- data.tar.gz: 67ceffa7c755f7460c0806675cae0bd72176100ca8b9abd6842eabe71ef091dd4b3876bdd8fd4119e9b84148d3401091d1d0ab9eb75b144d8c4b07747b4edf39
6
+ metadata.gz: c0f524cebcb6b5802d807abe9bfc403920228876865904f76c63378bc5f275b2ec5a67c40c4ce887c776ab1059d17381c1cfa38f7e4cd3780683e12b18ce891e
7
+ data.tar.gz: 3e7a3154d57be416a2a0908111a1da3833570334097523db9e2d677bdda2966ee8f576fb559244c77a6aa59cb0d46ed5798cf73f9b171aa8026bd9e1cd2be4c7
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ === 2.1.0 (2025-05-06)
2
+
3
+ * Support custom html validation via Capybara.custom_html_validation (jeremyevans)
4
+
1
5
  === 2.0.0 (2024-12-31)
2
6
 
3
7
  * Remove runtime dependency on minitest and minitest-global_expectations (jeremyevans)
data/README.rdoc CHANGED
@@ -44,6 +44,18 @@ Source code is available on GitHub at https://github.com/jeremyevans/capybara-va
44
44
  end
45
45
  end
46
46
 
47
+ = Custom HTML Validation
48
+
49
+ You can perform your own custom validation of HTML elements, by calling
50
+ +Capybara.custom_html_validation+. This will be passed the Nokogiri document
51
+ and a block, and should call the block with any Nokogiri elements that are
52
+ considered invalid:
53
+
54
+ Capybara.custom_html_validation do |doc, &block|
55
+ s = "*[required=true], *[required=false], input[checked=true], input[checked=false]"
56
+ doc.css(s).map(&block)
57
+ end
58
+
47
59
  = License
48
60
 
49
61
  MIT
@@ -30,7 +30,16 @@ module Capybara
30
30
  # HTML validation, validate the HTML and expect no errors.
31
31
  def dom
32
32
  unless @dom || @skip_html_validation
33
- errors = Nokogiri::HTML5(html, max_errors: 10).errors
33
+ doc = Nokogiri::HTML5(html, max_errors: 10)
34
+ errors = doc.errors
35
+
36
+ if errors.empty?
37
+ custom_html_validation(doc) do |element|
38
+ errors << element
39
+ break if errors.length >= 10
40
+ end
41
+ end
42
+
34
43
  unless errors.empty?
35
44
  called_from = caller_locations.detect do |loc|
36
45
  loc.path !~ %r{lib/(capybara|nokogiri|minitest)}
@@ -60,6 +69,15 @@ END_MSG
60
69
  def base_href
61
70
  skip_html_validation{super}
62
71
  end
72
+
73
+ private
74
+
75
+ # Perform any custom HTML validation
76
+ def custom_html_validation(doc, &block)
77
+ # nothing by default
78
+ end
79
+ # Avoid method override warnings
80
+ alias custom_html_validation custom_html_validation
63
81
  end
64
82
 
65
83
  RackTest::Browser.prepend(RackTest::ValidateDom)
@@ -70,4 +88,16 @@ END_MSG
70
88
  page.driver.browser.skip_html_validation(&block)
71
89
  end
72
90
  end
91
+
92
+ # Define custom validation to use, in addition to standard HTML5 validation.
93
+ # This can allow you to detect and raise errors for issues that are not
94
+ # caught by Nokogiri's HTML5 validation.
95
+ def self.custom_html_validation(&block)
96
+ RackTest::ValidateDom.class_eval do
97
+ define_method(:custom_html_validation, &block)
98
+ alias_method(:custom_html_validation, :custom_html_validation)
99
+ private(:custom_html_validation)
100
+ end
101
+ nil
102
+ end
73
103
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-validate_html5
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2024-12-31 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rack-test
@@ -74,9 +74,9 @@ email: code@jeremyevans.net
74
74
  executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files:
77
- - README.rdoc
78
77
  - CHANGELOG
79
78
  - MIT-LICENSE
79
+ - README.rdoc
80
80
  files:
81
81
  - CHANGELOG
82
82
  - MIT-LICENSE
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  requirements: []
114
- rubygems_version: 3.6.2
114
+ rubygems_version: 3.6.7
115
115
  specification_version: 4
116
116
  summary: Validate HTML5 for each page parsed
117
117
  test_files: []