capybara-validate_html5 1.0.0 → 1.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: abeb0e5a54618097048f3476bc49bf454afe6bff7ac5ccb56ac46bdf4ec0ea12
4
- data.tar.gz: a2f0356a2d583be4d9c985803bc809df7dd4e8ad71b9c96a524d037f756ae346
3
+ metadata.gz: a9d1ef7637dc132bd66e5f979be8d9ef5020f8da97cfa24347a00e3888ed12a0
4
+ data.tar.gz: 5121a990aeda11d5cbc89651d00b1a57eda970c9f8670bf82f49d41bb20f30ae
5
5
  SHA512:
6
- metadata.gz: c93d81860de762973748165f13192543cc546ec3f0d5d2ed07bf60e70ac429675f0f1a4cff4bdc625d126806640f6221510f85c2f320ea2533ea676b9b8dcbbb
7
- data.tar.gz: d612c465456403978375ec3059e0fdb47df0a7658f149f3a0f9777d3340cfe1a88bd16f000fb8bdf176adabeb765a068330f481aed6af5bc7f6bcd4112189579
6
+ metadata.gz: e331ed3df13debeaf4e3131490ebb1e35508edd5db23da0d103164873f1c0bdebffa3a527cb0e990ed4f4ff3736cb62010ea6b060296117c0b7d8068e77ce233
7
+ data.tar.gz: 1d33645a992b0b6ff288909bcbc9ad7cfe2a867b4e585c65b212266de8e07cb71b4c58d5ed7ba1c2941f773b1f36e27bcc413796c711c5d986e0787acc84d81d
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ === 1.1.0 (2022-05-26)
2
+
3
+ * Make error output more friendly, showing error message and HTML for each error (jeremyevans)
4
+
5
+ * Require html5 validation by default, use capybara/optionally_validate_html5 for previous behavior (jeremyevans)
6
+
7
+ * Work with capybara 3.37.0 (jeremyevans)
8
+
1
9
  === 1.0.0 (2022-03-07)
2
10
 
3
11
  * Initial Public Release
data/README.rdoc CHANGED
@@ -5,7 +5,8 @@ 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.
8
+ This only works for the rack-test driver, and only works when using
9
+ minitest-global_expectations for testing.
9
10
 
10
11
  = Installation
11
12
 
@@ -19,8 +20,9 @@ Source code is available on GitHub at https://github.com/jeremyevans/capybara-va
19
20
 
20
21
  require 'capybara'
21
22
  require 'capybara/validate_html5'
23
+ require 'minitest/global_expectations'
22
24
 
23
- describe Capybara::RestoreState do
25
+ describe 'capybara-validate_html5' do
24
26
  include Rack::Test::Methods
25
27
  include Capybara::DSL
26
28
 
@@ -0,0 +1,12 @@
1
+ require 'capybara'
2
+
3
+ if Capybara.respond_to?(:use_html5_parsing) && defined?(Nokogiri::HTML5)
4
+ require_relative 'validate_html5'
5
+ else
6
+ module Capybara::DSL
7
+ # If HTML5 validation isn't supported, make this a no-op.
8
+ def skip_html_validation
9
+ yield
10
+ end
11
+ end
12
+ end
@@ -1,63 +1,68 @@
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
+ unless Capybara.respond_to?(:use_html5_parsing) && defined?(Nokogiri::HTML5)
5
+ 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
+ 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
+ self.use_html5_parsing = true
9
+
10
+ require 'capybara/rack_test/browser'
11
+ require 'capybara/dsl'
12
+ require 'minitest'
36
13
 
37
- #{html.split("\n")[begin_line..end_line].join("\n")}
14
+ module RackTest::ValidateDom
15
+ # Skip HTML validation inside the block.
16
+ def skip_html_validation
17
+ skip = @skip_html_validation
18
+ @skip_html_validation = true
19
+ yield
20
+ ensure
21
+ @skip_html_validation = skip
22
+ end
23
+
24
+ # If loading the DOM for the first time and not skipping
25
+ # HTML validation, validate the HTML and expect no errors.
26
+ def dom
27
+ unless @dom || @skip_html_validation
28
+ errors = Nokogiri::HTML5(html, max_errors: 10).errors
29
+ unless errors.empty?
30
+ called_from = caller_locations.detect do |loc|
31
+ loc.path !~ %r{lib/(capybara|nokogiri|minitest)}
32
+ end
33
+ html_lines = html.split("\n").map.with_index{|line, i| "#{sprintf("%6i", i+1)}: #{line}"}
34
+ error_info = String.new
35
+ error_info << (<<END_MSG)
36
+ invalid HTML on page returned for #{last_request.path}, called from #{called_from.path}:#{called_from.lineno}
38
37
 
39
38
  END_MSG
39
+
40
+ errors.each do |error|
41
+ error_line = error.line
42
+ begin_line = error_line - 3
43
+ end_line = error_line + 3
44
+ begin_line = 0 if begin_line < 0
45
+ error_info << error.to_s << "\n" << html_lines[begin_line..end_line].join("\n") << "\n\n"
40
46
  end
47
+
48
+ errors.size.must_equal(0, error_info)
41
49
  end
42
- super
43
50
  end
51
+ super
44
52
  end
45
53
 
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
54
+ # Skip HTML validation during base_href calculations.
55
+ def base_href
56
+ skip_html_validation{super}
53
57
  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
58
+ end
59
+
60
+ RackTest::Browser.prepend(RackTest::ValidateDom)
61
+
62
+ module DSL
63
+ # Skip HTML validation inside the block.
64
+ def skip_html_validation(&block)
65
+ page.driver.browser.skip_html_validation(&block)
61
66
  end
62
67
  end
63
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-07 00:00:00.000000000 Z
11
+ date: 2022-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-test
@@ -82,6 +82,7 @@ files:
82
82
  - CHANGELOG
83
83
  - MIT-LICENSE
84
84
  - README.rdoc
85
+ - lib/capybara/optionally_validate_html5.rb
85
86
  - lib/capybara/validate_html5.rb
86
87
  homepage: http://github.com/jeremyevans/capybara-validate_html5
87
88
  licenses: