capybara-validate_html5 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: abeb0e5a54618097048f3476bc49bf454afe6bff7ac5ccb56ac46bdf4ec0ea12
4
+ data.tar.gz: a2f0356a2d583be4d9c985803bc809df7dd4e8ad71b9c96a524d037f756ae346
5
+ SHA512:
6
+ metadata.gz: c93d81860de762973748165f13192543cc546ec3f0d5d2ed07bf60e70ac429675f0f1a4cff4bdc625d126806640f6221510f85c2f320ea2533ea676b9b8dcbbb
7
+ data.tar.gz: d612c465456403978375ec3059e0fdb47df0a7658f149f3a0f9777d3340cfe1a88bd16f000fb8bdf176adabeb765a068330f481aed6af5bc7f6bcd4112189579
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ === 1.0.0 (2022-03-07)
2
+
3
+ * Initial Public Release
data/MIT-LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2022 Jeremy Evans
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = capybara-validate_html5
2
+
3
+ capybara-validate_html5 validates the HTML5 for each page accessed, and
4
+ fails if there are any HTML5 parse errors on the page. This makes
5
+ it easy to automatically test for HTML5 validity when running your
6
+ normal capybara test suite.
7
+
8
+ This only works for the rack-test driver.
9
+
10
+ = Installation
11
+
12
+ gem install capybara-validate_html5
13
+
14
+ = Source Code
15
+
16
+ Source code is available on GitHub at https://github.com/jeremyevans/capybara-validate_html5
17
+
18
+ = Examples
19
+
20
+ require 'capybara'
21
+ require 'capybara/validate_html5'
22
+
23
+ describe Capybara::RestoreState do
24
+ include Rack::Test::Methods
25
+ include Capybara::DSL
26
+
27
+ def app
28
+ MyRackApp
29
+ end
30
+
31
+ it "should allow restoring of state" do
32
+ visit '/' # validates HTML, fails spec if not valid
33
+
34
+ skip_html_validation do
35
+ click_button 'Submit' # doesn't validate resulting HTML
36
+ end
37
+
38
+ click_link 'Go Somewhere' # validates HTML, fails spec if not valid
39
+ end
40
+ end
41
+
42
+ = License
43
+
44
+ MIT
45
+
46
+ = Author
47
+
48
+ Jeremy Evans <code@jeremyevans.net>
@@ -0,0 +1,63 @@
1
+ require 'capybara'
2
+
3
+ module Capybara
4
+ if respond_to?(:use_html5_parsing) && defined?(Nokogiri::HTML5)
5
+ self.use_html5_parsing = true
6
+
7
+ require 'capybara/rack_test/browser'
8
+ require 'capybara/dsl'
9
+ require 'minitest'
10
+
11
+ module RackTest::ValidateDom
12
+ # Skip HTML validation inside the block.
13
+ def skip_html_validation
14
+ skip = @skip_html_validation
15
+ @skip_html_validation = true
16
+ yield
17
+ ensure
18
+ @skip_html_validation = skip
19
+ end
20
+
21
+ # If loading the DOM for the first time and not skipping
22
+ # HTML validation, validate the HTML and expect no errors.
23
+ def dom
24
+ unless @dom || @skip_html_validation
25
+ errors = Nokogiri::HTML5(html, max_errors: 10).errors
26
+ unless errors.empty?
27
+ first_error_line = errors.first.line
28
+ begin_line = first_error_line - 3
29
+ end_line = first_error_line + 3
30
+ begin_line = 0 if begin_line < 0
31
+ called_from = caller_locations.detect do |loc|
32
+ loc.path !~ %r{lib/(capybara|nokogiri|minitest)}
33
+ end
34
+ errors.must_be_empty(<<END_MSG)
35
+ invalid HTML on page returned for #{last_request.path}, called from #{called_from.path}:#{called_from.lineno}
36
+
37
+ #{html.split("\n")[begin_line..end_line].join("\n")}
38
+
39
+ END_MSG
40
+ end
41
+ end
42
+ super
43
+ end
44
+ end
45
+
46
+ RackTest::Browser.prepend(RackTest::ValidateDom)
47
+
48
+ module DSL
49
+ # Skip HTML validation inside the block.
50
+ def skip_html_validation(&block)
51
+ page.driver.browser.skip_html_validation(&block)
52
+ end
53
+ end
54
+ else
55
+ module DSL
56
+ # If HTML5 validation isn't supported, make this
57
+ # a no-op.
58
+ def skip_html_validation(&block)
59
+ yield
60
+ end
61
+ end
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-validate_html5
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Evans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack-test
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capybara
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-global_expectations
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: |
70
+ capybara-validate validates the HTML5 for each page accessed, and
71
+ fails if there are any HTML5 parse errors on the page. This makes
72
+ it easy to automatically test for HTML5 validity when running your
73
+ normal capybara test suite.
74
+ email: code@jeremyevans.net
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files:
78
+ - README.rdoc
79
+ - CHANGELOG
80
+ - MIT-LICENSE
81
+ files:
82
+ - CHANGELOG
83
+ - MIT-LICENSE
84
+ - README.rdoc
85
+ - lib/capybara/validate_html5.rb
86
+ homepage: http://github.com/jeremyevans/capybara-validate_html5
87
+ licenses:
88
+ - MIT
89
+ metadata:
90
+ bug_tracker_uri: https://github.com/jeremyevans/capybara-validate_html5/issues
91
+ changelog_uri: https://github.com/jeremyevans/capybara-validate_html5/blob/master/CHANGELOG
92
+ source_code_uri: https://github.com/jeremyevans/capybara-validate_html5
93
+ post_install_message:
94
+ rdoc_options:
95
+ - "--quiet"
96
+ - "--line-numbers"
97
+ - "--inline-source"
98
+ - "--title"
99
+ - 'capybara-validate: Validate HTML5 for each page accessed'
100
+ - "--main"
101
+ - README.rdoc
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubygems_version: 3.3.7
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Validate HTML5 for each page accessed
119
+ test_files: []