capybara-validate_html5 1.1.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 +4 -4
- data/CHANGELOG +8 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +24 -9
- data/lib/capybara/optionally_validate_html5.rb +2 -0
- data/lib/capybara/validate_html5.rb +38 -3
- metadata +9 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2b1d78fdef99821bc035edd33ace215061c0393e561ecf3033655a48d1e1f39
|
4
|
+
data.tar.gz: e30b30b5ec5522421a9f4a3fa340470a88437126ef259da24a4878ff1e3673d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0f524cebcb6b5802d807abe9bfc403920228876865904f76c63378bc5f275b2ec5a67c40c4ce887c776ab1059d17381c1cfa38f7e4cd3780683e12b18ce891e
|
7
|
+
data.tar.gz: 3e7a3154d57be416a2a0908111a1da3833570334097523db9e2d677bdda2966ee8f576fb559244c77a6aa59cb0d46ed5798cf73f9b171aa8026bd9e1cd2be4c7
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
=== 2.1.0 (2025-05-06)
|
2
|
+
|
3
|
+
* Support custom html validation via Capybara.custom_html_validation (jeremyevans)
|
4
|
+
|
5
|
+
=== 2.0.0 (2024-12-31)
|
6
|
+
|
7
|
+
* Remove runtime dependency on minitest and minitest-global_expectations (jeremyevans)
|
8
|
+
|
1
9
|
=== 1.1.0 (2022-05-26)
|
2
10
|
|
3
11
|
* Make error output more friendly, showing error message and HTML for each error (jeremyevans)
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
= capybara-validate_html5
|
2
2
|
|
3
|
-
capybara-validate_html5 validates the HTML5 for each page
|
3
|
+
capybara-validate_html5 validates the HTML5 for each page parsed, and
|
4
4
|
fails if there are any HTML5 parse errors on the page. This makes
|
5
5
|
it easy to automatically test for HTML5 validity when running your
|
6
6
|
normal capybara test suite.
|
7
7
|
|
8
|
-
This only works for the rack-test driver
|
9
|
-
minitest-global_expectations for testing.
|
8
|
+
This only works for the rack-test driver.
|
10
9
|
|
11
10
|
= Installation
|
12
11
|
|
@@ -18,9 +17,7 @@ Source code is available on GitHub at https://github.com/jeremyevans/capybara-va
|
|
18
17
|
|
19
18
|
= Examples
|
20
19
|
|
21
|
-
require 'capybara'
|
22
20
|
require 'capybara/validate_html5'
|
23
|
-
require 'minitest/global_expectations'
|
24
21
|
|
25
22
|
describe 'capybara-validate_html5' do
|
26
23
|
include Rack::Test::Methods
|
@@ -31,16 +28,34 @@ Source code is available on GitHub at https://github.com/jeremyevans/capybara-va
|
|
31
28
|
end
|
32
29
|
|
33
30
|
it "should allow restoring of state" do
|
34
|
-
visit '/' #
|
31
|
+
visit '/' # No validation on retrieval
|
32
|
+
page.body # No validation on body access
|
35
33
|
|
34
|
+
page.all("a") # Attempt to parse body, validates HTML, raises exception if not valid
|
35
|
+
page.all("a") # No validation, as same body already parsed
|
36
|
+
|
37
|
+
visit '/page1'
|
38
|
+
click_link 'Go Somewhere' # Attempt to parse body, validates HTML, raises exception if not valid
|
39
|
+
|
40
|
+
visit '/page2'
|
36
41
|
skip_html_validation do
|
37
|
-
click_button 'Submit' #
|
42
|
+
click_button 'Submit' # No validation, as it was explicitly skipped
|
38
43
|
end
|
39
|
-
|
40
|
-
click_link 'Go Somewhere' # validates HTML, fails spec if not valid
|
41
44
|
end
|
42
45
|
end
|
43
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
|
+
|
44
59
|
= License
|
45
60
|
|
46
61
|
MIT
|
@@ -2,6 +2,7 @@ require 'capybara'
|
|
2
2
|
|
3
3
|
if Capybara.respond_to?(:use_html5_parsing) && defined?(Nokogiri::HTML5)
|
4
4
|
require_relative 'validate_html5'
|
5
|
+
# :nocov:
|
5
6
|
else
|
6
7
|
module Capybara::DSL
|
7
8
|
# If HTML5 validation isn't supported, make this a no-op.
|
@@ -9,4 +10,5 @@ else
|
|
9
10
|
yield
|
10
11
|
end
|
11
12
|
end
|
13
|
+
# :nocov:
|
12
14
|
end
|
@@ -1,15 +1,20 @@
|
|
1
1
|
require 'capybara'
|
2
2
|
|
3
3
|
module Capybara
|
4
|
+
# Exception class raised for HTML5 validations
|
5
|
+
class HTML5ValidationError < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
# :nocov:
|
4
9
|
unless Capybara.respond_to?(:use_html5_parsing) && defined?(Nokogiri::HTML5)
|
5
10
|
raise LoadError, "capybara-validate_html5 cannot be used as Capybara or Nokogiri doesn't support HTML5 parsing (require capybara/optionally_validate_html5 to make validation optional)"
|
6
11
|
end
|
12
|
+
# :nocov:
|
7
13
|
|
8
14
|
self.use_html5_parsing = true
|
9
15
|
|
10
16
|
require 'capybara/rack_test/browser'
|
11
17
|
require 'capybara/dsl'
|
12
|
-
require 'minitest'
|
13
18
|
|
14
19
|
module RackTest::ValidateDom
|
15
20
|
# Skip HTML validation inside the block.
|
@@ -25,7 +30,16 @@ module Capybara
|
|
25
30
|
# HTML validation, validate the HTML and expect no errors.
|
26
31
|
def dom
|
27
32
|
unless @dom || @skip_html_validation
|
28
|
-
|
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
|
+
|
29
43
|
unless errors.empty?
|
30
44
|
called_from = caller_locations.detect do |loc|
|
31
45
|
loc.path !~ %r{lib/(capybara|nokogiri|minitest)}
|
@@ -45,7 +59,7 @@ END_MSG
|
|
45
59
|
error_info << error.to_s << "\n" << html_lines[begin_line..end_line].join("\n") << "\n\n"
|
46
60
|
end
|
47
61
|
|
48
|
-
errors.size
|
62
|
+
raise HTML5ValidationError, "#{errors.size} HTML5 validation errors: #{error_info}"
|
49
63
|
end
|
50
64
|
end
|
51
65
|
super
|
@@ -55,6 +69,15 @@ END_MSG
|
|
55
69
|
def base_href
|
56
70
|
skip_html_validation{super}
|
57
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
|
58
81
|
end
|
59
82
|
|
60
83
|
RackTest::Browser.prepend(RackTest::ValidateDom)
|
@@ -65,4 +88,16 @@ END_MSG
|
|
65
88
|
page.driver.browser.skip_html_validation(&block)
|
66
89
|
end
|
67
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
|
68
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-validate_html5
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rack-test
|
@@ -45,7 +44,7 @@ dependencies:
|
|
45
44
|
- - ">="
|
46
45
|
- !ruby/object:Gem::Version
|
47
46
|
version: '0'
|
48
|
-
type: :
|
47
|
+
type: :development
|
49
48
|
prerelease: false
|
50
49
|
version_requirements: !ruby/object:Gem::Requirement
|
51
50
|
requirements:
|
@@ -59,7 +58,7 @@ dependencies:
|
|
59
58
|
- - ">="
|
60
59
|
- !ruby/object:Gem::Version
|
61
60
|
version: '0'
|
62
|
-
type: :
|
61
|
+
type: :development
|
63
62
|
prerelease: false
|
64
63
|
version_requirements: !ruby/object:Gem::Requirement
|
65
64
|
requirements:
|
@@ -67,7 +66,7 @@ dependencies:
|
|
67
66
|
- !ruby/object:Gem::Version
|
68
67
|
version: '0'
|
69
68
|
description: |
|
70
|
-
capybara-validate validates the HTML5 for each page
|
69
|
+
capybara-validate validates the HTML5 for each page parsed, and
|
71
70
|
fails if there are any HTML5 parse errors on the page. This makes
|
72
71
|
it easy to automatically test for HTML5 validity when running your
|
73
72
|
normal capybara test suite.
|
@@ -75,9 +74,9 @@ email: code@jeremyevans.net
|
|
75
74
|
executables: []
|
76
75
|
extensions: []
|
77
76
|
extra_rdoc_files:
|
78
|
-
- README.rdoc
|
79
77
|
- CHANGELOG
|
80
78
|
- MIT-LICENSE
|
79
|
+
- README.rdoc
|
81
80
|
files:
|
82
81
|
- CHANGELOG
|
83
82
|
- MIT-LICENSE
|
@@ -91,13 +90,12 @@ metadata:
|
|
91
90
|
bug_tracker_uri: https://github.com/jeremyevans/capybara-validate_html5/issues
|
92
91
|
changelog_uri: https://github.com/jeremyevans/capybara-validate_html5/blob/master/CHANGELOG
|
93
92
|
source_code_uri: https://github.com/jeremyevans/capybara-validate_html5
|
94
|
-
post_install_message:
|
95
93
|
rdoc_options:
|
96
94
|
- "--quiet"
|
97
95
|
- "--line-numbers"
|
98
96
|
- "--inline-source"
|
99
97
|
- "--title"
|
100
|
-
- 'capybara-validate: Validate HTML5 for each page
|
98
|
+
- 'capybara-validate: Validate HTML5 for each page parsed'
|
101
99
|
- "--main"
|
102
100
|
- README.rdoc
|
103
101
|
require_paths:
|
@@ -113,8 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
111
|
- !ruby/object:Gem::Version
|
114
112
|
version: '0'
|
115
113
|
requirements: []
|
116
|
-
rubygems_version: 3.
|
117
|
-
signing_key:
|
114
|
+
rubygems_version: 3.6.7
|
118
115
|
specification_version: 4
|
119
|
-
summary: Validate HTML5 for each page
|
116
|
+
summary: Validate HTML5 for each page parsed
|
120
117
|
test_files: []
|