capybara-validate_html5 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abeb0e5a54618097048f3476bc49bf454afe6bff7ac5ccb56ac46bdf4ec0ea12
4
- data.tar.gz: a2f0356a2d583be4d9c985803bc809df7dd4e8ad71b9c96a524d037f756ae346
3
+ metadata.gz: 0f32ed1925ec14c9311dd217c9b7d0639d79fef0040d5b6f21393f5553267ec3
4
+ data.tar.gz: a39dab6f833867d06d5cac1260693588885788f3de193234b1789a71121d737e
5
5
  SHA512:
6
- metadata.gz: c93d81860de762973748165f13192543cc546ec3f0d5d2ed07bf60e70ac429675f0f1a4cff4bdc625d126806640f6221510f85c2f320ea2533ea676b9b8dcbbb
7
- data.tar.gz: d612c465456403978375ec3059e0fdb47df0a7658f149f3a0f9777d3340cfe1a88bd16f000fb8bdf176adabeb765a068330f481aed6af5bc7f6bcd4112189579
6
+ metadata.gz: cf51d9e611941e92ab1c5aeca7b9d70e660e39a72ff07d95d8fe8389160095141fa8a67d6ef5493d455216c539e5745dbf851d3558fe47abdf32d96fa4f7230f
7
+ data.tar.gz: 67ceffa7c755f7460c0806675cae0bd72176100ca8b9abd6842eabe71ef091dd4b3876bdd8fd4119e9b84148d3401091d1d0ab9eb75b144d8c4b07747b4edf39
data/CHANGELOG CHANGED
@@ -1,3 +1,15 @@
1
+ === 2.0.0 (2024-12-31)
2
+
3
+ * Remove runtime dependency on minitest and minitest-global_expectations (jeremyevans)
4
+
5
+ === 1.1.0 (2022-05-26)
6
+
7
+ * Make error output more friendly, showing error message and HTML for each error (jeremyevans)
8
+
9
+ * Require html5 validation by default, use capybara/optionally_validate_html5 for previous behavior (jeremyevans)
10
+
11
+ * Work with capybara 3.37.0 (jeremyevans)
12
+
1
13
  === 1.0.0 (2022-03-07)
2
14
 
3
15
  * Initial Public Release
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2022 Jeremy Evans
1
+ Copyright (c) 2022-2024 Jeremy Evans
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = capybara-validate_html5
2
2
 
3
- capybara-validate_html5 validates the HTML5 for each page accessed, and
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.
@@ -17,10 +17,9 @@ Source code is available on GitHub at https://github.com/jeremyevans/capybara-va
17
17
 
18
18
  = Examples
19
19
 
20
- require 'capybara'
21
20
  require 'capybara/validate_html5'
22
21
 
23
- describe Capybara::RestoreState do
22
+ describe 'capybara-validate_html5' do
24
23
  include Rack::Test::Methods
25
24
  include Capybara::DSL
26
25
 
@@ -29,13 +28,19 @@ Source code is available on GitHub at https://github.com/jeremyevans/capybara-va
29
28
  end
30
29
 
31
30
  it "should allow restoring of state" do
32
- visit '/' # validates HTML, fails spec if not valid
31
+ visit '/' # No validation on retrieval
32
+ page.body # No validation on body access
33
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'
34
41
  skip_html_validation do
35
- click_button 'Submit' # doesn't validate resulting HTML
42
+ click_button 'Submit' # No validation, as it was explicitly skipped
36
43
  end
37
-
38
- click_link 'Go Somewhere' # validates HTML, fails spec if not valid
39
44
  end
40
45
  end
41
46
 
@@ -0,0 +1,14 @@
1
+ require 'capybara'
2
+
3
+ if Capybara.respond_to?(:use_html5_parsing) && defined?(Nokogiri::HTML5)
4
+ require_relative 'validate_html5'
5
+ # :nocov:
6
+ else
7
+ module Capybara::DSL
8
+ # If HTML5 validation isn't supported, make this a no-op.
9
+ def skip_html_validation
10
+ yield
11
+ end
12
+ end
13
+ # :nocov:
14
+ end
@@ -1,63 +1,73 @@
1
1
  require 'capybara'
2
2
 
3
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
4
+ # Exception class raised for HTML5 validations
5
+ class HTML5ValidationError < StandardError
6
+ end
20
7
 
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}
8
+ # :nocov:
9
+ unless Capybara.respond_to?(:use_html5_parsing) && defined?(Nokogiri::HTML5)
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)"
11
+ end
12
+ # :nocov:
36
13
 
37
- #{html.split("\n")[begin_line..end_line].join("\n")}
14
+ self.use_html5_parsing = true
15
+
16
+ require 'capybara/rack_test/browser'
17
+ require 'capybara/dsl'
18
+
19
+ module RackTest::ValidateDom
20
+ # Skip HTML validation inside the block.
21
+ def skip_html_validation
22
+ skip = @skip_html_validation
23
+ @skip_html_validation = true
24
+ yield
25
+ ensure
26
+ @skip_html_validation = skip
27
+ end
28
+
29
+ # If loading the DOM for the first time and not skipping
30
+ # HTML validation, validate the HTML and expect no errors.
31
+ def dom
32
+ unless @dom || @skip_html_validation
33
+ errors = Nokogiri::HTML5(html, max_errors: 10).errors
34
+ unless errors.empty?
35
+ called_from = caller_locations.detect do |loc|
36
+ loc.path !~ %r{lib/(capybara|nokogiri|minitest)}
37
+ end
38
+ html_lines = html.split("\n").map.with_index{|line, i| "#{sprintf("%6i", i+1)}: #{line}"}
39
+ error_info = String.new
40
+ error_info << (<<END_MSG)
41
+ invalid HTML on page returned for #{last_request.path}, called from #{called_from.path}:#{called_from.lineno}
38
42
 
39
43
  END_MSG
44
+
45
+ errors.each do |error|
46
+ error_line = error.line
47
+ begin_line = error_line - 3
48
+ end_line = error_line + 3
49
+ begin_line = 0 if begin_line < 0
50
+ error_info << error.to_s << "\n" << html_lines[begin_line..end_line].join("\n") << "\n\n"
40
51
  end
52
+
53
+ raise HTML5ValidationError, "#{errors.size} HTML5 validation errors: #{error_info}"
41
54
  end
42
- super
43
55
  end
56
+ super
44
57
  end
45
58
 
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
59
+ # Skip HTML validation during base_href calculations.
60
+ def base_href
61
+ skip_html_validation{super}
53
62
  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
63
+ end
64
+
65
+ RackTest::Browser.prepend(RackTest::ValidateDom)
66
+
67
+ module DSL
68
+ # Skip HTML validation inside the block.
69
+ def skip_html_validation(&block)
70
+ page.driver.browser.skip_html_validation(&block)
61
71
  end
62
72
  end
63
73
  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: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-03-07 00:00:00.000000000 Z
10
+ date: 2024-12-31 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: :runtime
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: :runtime
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 accessed, and
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.
@@ -82,6 +81,7 @@ files:
82
81
  - CHANGELOG
83
82
  - MIT-LICENSE
84
83
  - README.rdoc
84
+ - lib/capybara/optionally_validate_html5.rb
85
85
  - lib/capybara/validate_html5.rb
86
86
  homepage: http://github.com/jeremyevans/capybara-validate_html5
87
87
  licenses:
@@ -90,13 +90,12 @@ metadata:
90
90
  bug_tracker_uri: https://github.com/jeremyevans/capybara-validate_html5/issues
91
91
  changelog_uri: https://github.com/jeremyevans/capybara-validate_html5/blob/master/CHANGELOG
92
92
  source_code_uri: https://github.com/jeremyevans/capybara-validate_html5
93
- post_install_message:
94
93
  rdoc_options:
95
94
  - "--quiet"
96
95
  - "--line-numbers"
97
96
  - "--inline-source"
98
97
  - "--title"
99
- - 'capybara-validate: Validate HTML5 for each page accessed'
98
+ - 'capybara-validate: Validate HTML5 for each page parsed'
100
99
  - "--main"
101
100
  - README.rdoc
102
101
  require_paths:
@@ -112,8 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
111
  - !ruby/object:Gem::Version
113
112
  version: '0'
114
113
  requirements: []
115
- rubygems_version: 3.3.7
116
- signing_key:
114
+ rubygems_version: 3.6.2
117
115
  specification_version: 4
118
- summary: Validate HTML5 for each page accessed
116
+ summary: Validate HTML5 for each page parsed
119
117
  test_files: []