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 +4 -4
- data/CHANGELOG +4 -0
- data/README.rdoc +12 -0
- data/lib/capybara/validate_html5.rb +31 -1
- metadata +4 -4
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
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
|
-
|
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.
|
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:
|
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.
|
114
|
+
rubygems_version: 3.6.7
|
115
115
|
specification_version: 4
|
116
116
|
summary: Validate HTML5 for each page parsed
|
117
117
|
test_files: []
|