w3c_rspec_validators 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +0 -4
- data/lib/w3c_rspec_validators/config.rb +4 -4
- data/lib/w3c_rspec_validators/rspec.rb +4 -4
- data/lib/w3c_rspec_validators/validator.rb +5 -3
- data/lib/w3c_rspec_validators/version.rb +1 -1
- data/spec/css_files_spec.rb +12 -6
- data/spec/error_parser_spec.rb +9 -7
- data/spec/matchers_spec.rb +29 -20
- data/spec/validator_spec.rb +13 -12
- metadata +29 -23
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e38ccd736f2de04563e2b28fa08369342aaa4e9a9e76945f36a17f9ee453f499
|
4
|
+
data.tar.gz: a003e4dac5b1960593ea848d0f1d0e4bad9ec031105330ac9fa25bbb8e4e2c30
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ffa189cb7fe33744cbc17d6bf7fdcbd4ab293a08df7b4400d6511ebb34dd9d3d0ebca0cf3000bec41e8b99206f1cbc30202ad5e0d7da38a4b11dbf4ee7880aa9
|
7
|
+
data.tar.gz: 82dafcdbfd4b52047035a64acef9e9601ea093b40541ff2174ed92ce677cf3a9adb03b2c08f26349a9c0b037403ced185bbcc9c9bac89175f1e3a3628c70398d
|
data/Gemfile
CHANGED
@@ -2,10 +2,6 @@ source "http://rubygems.org"
|
|
2
2
|
|
3
3
|
gem "w3c_validators"
|
4
4
|
gem "rspec"
|
5
|
-
gem "linecache19", git: "git://github.com/mark-moseley/linecache", require: "ruby-debug"
|
6
|
-
gem "ruby-debug-base19x", "~> 0.11.30.pre4"
|
7
|
-
gem "ruby-debug19"
|
8
|
-
|
9
5
|
|
10
6
|
# Specify your gem's dependencies in w3c_rspec_validators.gemspec
|
11
7
|
gemspec
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "rails"
|
2
2
|
|
3
3
|
module W3cRspecValidators
|
4
|
-
|
4
|
+
|
5
5
|
class Railtie < Rails::Railtie
|
6
6
|
initializer "initialize config" do
|
7
7
|
config_file = Rails.root.join("config", "w3c_rspec_validators.yml")
|
@@ -12,14 +12,14 @@ module W3cRspecValidators
|
|
12
12
|
# puts ActionDispatch::Routing::UrlFor::url_for("/")
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
class Config
|
17
17
|
@@config = {
|
18
|
-
validator_uri: ""
|
18
|
+
validator_uri: ""
|
19
19
|
}
|
20
20
|
|
21
21
|
def self.load! config_file
|
22
|
-
@@config = YAML.load(File.open(config_file))["config"]
|
22
|
+
@@config = YAML.load(File.open(config_file))["config"]
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.get
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module W3cRspecValidators
|
2
|
-
|
2
|
+
|
3
3
|
RSpec::Matchers.define :be_valid_html do
|
4
4
|
validator = Validator.new
|
5
5
|
match do |body|
|
6
6
|
validator.validate_html(body)
|
7
7
|
validator.response.errors.length == 0
|
8
8
|
end
|
9
|
-
|
9
|
+
failure_message do |actual|
|
10
10
|
validator.response.errors.map do |err|
|
11
11
|
ErrorParser.parse_html_error(err, actual)
|
12
12
|
end.join("\n")
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
RSpec::Matchers.define :be_valid_css do
|
17
17
|
validator = Validator.new
|
18
18
|
match do |css|
|
@@ -20,7 +20,7 @@ module W3cRspecValidators
|
|
20
20
|
validator.response.errors.length == 0
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
failure_message do |actual|
|
24
24
|
validator.response.errors.map do |err|
|
25
25
|
ErrorParser.parse_css_error(err, actual)
|
26
26
|
end.join("\n")
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module W3cRspecValidators
|
2
2
|
class Validator
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
3
5
|
attr_reader :response
|
4
6
|
include W3CValidators
|
5
7
|
|
6
8
|
def initialize
|
7
|
-
@html_validator =
|
9
|
+
@html_validator = NuValidator.new validator_uri: Config.get["w3c_service_uri"]
|
8
10
|
@css_validator = CSSValidator.new validator_uri: Config.get["w3c_css_service_uri"]
|
9
11
|
end
|
10
12
|
|
@@ -23,7 +25,7 @@ module W3cRspecValidators
|
|
23
25
|
@response = @html_validator.validate_text(text)
|
24
26
|
}
|
25
27
|
try validate
|
26
|
-
raise "Error: Invalid validation response! Tip: check if validator.nu engine is configured correctly" if @response.checked_by.blank?
|
28
|
+
raise Error, "Error: Invalid validation response! Tip: check if validator.nu engine is configured correctly" if @response.checked_by.blank?
|
27
29
|
@response
|
28
30
|
end
|
29
31
|
|
@@ -32,7 +34,7 @@ module W3cRspecValidators
|
|
32
34
|
@response = @css_validator.validate_text(text)
|
33
35
|
}
|
34
36
|
try validate
|
35
|
-
raise "Error: Invalid validation response! Tip: check if validator.nu engine is configured correctly" if @response.checked_by.blank?
|
37
|
+
raise Error, "Error: Invalid validation response! Tip: check if validator.nu engine is configured correctly" if @response.checked_by.blank?
|
36
38
|
@response
|
37
39
|
end
|
38
40
|
end
|
data/spec/css_files_spec.rb
CHANGED
@@ -2,17 +2,23 @@ require "w3c_rspec_validators"
|
|
2
2
|
|
3
3
|
describe "css_files" do
|
4
4
|
describe "self.compiled" do
|
5
|
-
|
5
|
+
|
6
6
|
before(:each) do
|
7
|
-
Object.
|
8
|
-
Rails.
|
9
|
-
FileUtils.
|
7
|
+
expect(Object).to receive(:system).with("rake -q assets:precompile")
|
8
|
+
expect(Rails).to receive(:root).and_return(Pathname.new("railsroot"))
|
9
|
+
expect(FileUtils).to receive(:rm_rf).with("railsroot/public/assets/")
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should read css files from a directory" do
|
13
13
|
directory = File.dirname(__FILE__)
|
14
|
-
|
15
|
-
|
14
|
+
|
15
|
+
compiled = W3cRspecValidators::CssFiles.compiled(["#{directory}/fixtures/*.css"])
|
16
|
+
|
17
|
+
expect(compiled).to eq <<~CSS
|
18
|
+
body {
|
19
|
+
}
|
20
|
+
#home {}
|
21
|
+
CSS
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
data/spec/error_parser_spec.rb
CHANGED
@@ -4,8 +4,8 @@ describe "error_parser" do
|
|
4
4
|
|
5
5
|
describe "self.parse_css" do
|
6
6
|
before(:each) do
|
7
|
-
@css_error_message = "ERROR; URI: file://localhost/TextArea; line 7:
|
8
|
-
|
7
|
+
@css_error_message = "ERROR; URI: file://localhost/TextArea; line 7:
|
8
|
+
|
9
9
|
Property foo doesn't exist :"
|
10
10
|
@css = "
|
11
11
|
body {
|
@@ -18,9 +18,10 @@ body {
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should properly format css errors" do
|
21
|
-
W3cRspecValidators::ErrorParser.parse_css_error(@css_error_message, @css)
|
22
|
-
|
23
|
-
|
21
|
+
error = W3cRspecValidators::ErrorParser.parse_css_error(@css_error_message, @css)
|
22
|
+
|
23
|
+
expect(error).to eq "######
|
24
|
+
Property foo doesn't exist :
|
24
25
|
Real code location(guessed) in File ../../app/assets/stylesheets/home.css.scss on line 2
|
25
26
|
|
26
27
|
Code context:
|
@@ -46,8 +47,9 @@ Code context:
|
|
46
47
|
end
|
47
48
|
|
48
49
|
it "should properly format a html error message" do
|
49
|
-
W3cRspecValidators::ErrorParser.parse_html_error(@html_error_message, @html)
|
50
|
-
|
50
|
+
error = W3cRspecValidators::ErrorParser.parse_html_error(@html_error_message, @html)
|
51
|
+
|
52
|
+
expect(error).to eq "######
|
51
53
|
line 7: An img element must have an alt attribute, except under certain conditions. For details, consult guidance on providing text alternatives for images.
|
52
54
|
|
53
55
|
</head>
|
data/spec/matchers_spec.rb
CHANGED
@@ -21,29 +21,37 @@ describe "rspec matchers" do
|
|
21
21
|
|
22
22
|
describe "be_valid_html" do
|
23
23
|
it "should be valid" do
|
24
|
-
|
24
|
+
body = <<~HTML
|
25
|
+
<!DOCTYPE HTML>
|
25
26
|
<html>
|
26
27
|
<head>
|
27
28
|
<title>dd</title>
|
28
29
|
</head>
|
29
30
|
<body>
|
30
31
|
</body>
|
31
|
-
</html>
|
32
|
+
</html>
|
33
|
+
HTML
|
34
|
+
|
35
|
+
expect(body).to be_valid_html
|
32
36
|
end
|
33
37
|
|
34
38
|
it "should not be valid" do
|
35
|
-
|
39
|
+
body = <<~HTML
|
40
|
+
<!DOCTYPE HTML>
|
36
41
|
<html>
|
37
42
|
<head>
|
38
43
|
<titled>dd</title>
|
39
44
|
</head>
|
40
45
|
<body></body>
|
41
|
-
</html>
|
46
|
+
</html>
|
47
|
+
HTML
|
48
|
+
|
49
|
+
expect(body).to_not be_valid_html
|
42
50
|
end
|
43
51
|
|
44
52
|
it "should complain about an missing src attribute" do
|
45
|
-
|
46
|
-
|
53
|
+
body = <<~HTML
|
54
|
+
<!DOCTYPE HTML>
|
47
55
|
<html>
|
48
56
|
<head>
|
49
57
|
<title>dd</title>
|
@@ -51,35 +59,36 @@ describe "rspec matchers" do
|
|
51
59
|
<body>
|
52
60
|
<img />
|
53
61
|
</body>
|
54
|
-
</html>
|
55
|
-
|
62
|
+
</html>
|
63
|
+
HTML
|
64
|
+
|
65
|
+
expect {
|
66
|
+
expect(body).to be_valid_html
|
67
|
+
}.to fail_matching(/line 7: Element “img” is missing required attr/m)
|
56
68
|
end
|
57
69
|
|
58
70
|
it "should use a custom uri if provided" do
|
59
|
-
W3cRspecValidators::Config.
|
60
|
-
|
61
|
-
validator = MarkupValidator.new
|
62
|
-
MarkupValidator.should_receive(:new).with(:validator_uri => "http://blubb.de").and_return validator
|
71
|
+
allow(W3cRspecValidators::Config).to receive(:get).and_return("w3c_service_uri" => "https://validator.nu/")
|
63
72
|
|
64
|
-
"
|
73
|
+
expect(NuValidator).to receive(:new).with(validator_uri: "https://validator.nu/").and_call_original
|
74
|
+
|
75
|
+
expect("dummy").to_not be_valid_html
|
65
76
|
end
|
66
77
|
end
|
67
78
|
|
68
79
|
describe "be_valid_css" do
|
69
80
|
it "should be valid" do
|
70
|
-
"body {}".
|
81
|
+
expect("body {}").to be_valid_css
|
71
82
|
end
|
72
83
|
|
73
84
|
it "should not be valid" do
|
74
|
-
"body { foo: 12px; }".
|
85
|
+
expect("body { foo: 12px; }").to_not be_valid_css
|
75
86
|
end
|
76
87
|
|
77
88
|
it "should not be valid" do
|
78
|
-
|
79
|
-
"body { foo: 12px; }".
|
80
|
-
}.
|
89
|
+
expect {
|
90
|
+
expect("body { foo: 12px; }").to be_valid_css
|
91
|
+
}.to fail_matching(/Property “foo” doesn't exist/)
|
81
92
|
end
|
82
|
-
|
83
93
|
end
|
84
|
-
|
85
94
|
end
|
data/spec/validator_spec.rb
CHANGED
@@ -5,9 +5,9 @@ describe W3cRspecValidators::Validator do
|
|
5
5
|
|
6
6
|
describe "initialize" do
|
7
7
|
it "should initialize MarkupValidator with config value" do
|
8
|
-
W3cRspecValidators::Config.
|
9
|
-
|
10
|
-
CSSValidator.
|
8
|
+
allow(W3cRspecValidators::Config).to receive(:get).and_return("w3c_service_uri" => "http://blubb.de", "w3c_css_service_uri" => "http://test.de")
|
9
|
+
expect(NuValidator).to receive(:new).with(validator_uri: "http://blubb.de")
|
10
|
+
expect(CSSValidator).to receive(:new).with(validator_uri: "http://test.de")
|
11
11
|
|
12
12
|
W3cRspecValidators::Validator.new
|
13
13
|
end
|
@@ -20,23 +20,24 @@ describe W3cRspecValidators::Validator do
|
|
20
20
|
""
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
|
-
|
23
|
+
|
24
|
+
allow_any_instance_of(NuValidator).to receive(:validate_text).and_return(Dummy.new)
|
25
|
+
|
25
26
|
expect {
|
26
|
-
W3cRspecValidators::Validator.new.
|
27
|
-
}.to raise_exception
|
27
|
+
W3cRspecValidators::Validator.new.validate_html("dummy")
|
28
|
+
}.to raise_exception(W3cRspecValidators::Validator::Error)
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
31
32
|
describe "error handling" do
|
32
33
|
it "should retry 3 times if there is a connection error" do
|
33
|
-
|
34
|
+
allow_any_instance_of(NuValidator).to receive(:validate_text).and_raise(StandardError)
|
34
35
|
validator = W3cRspecValidators::Validator.new
|
35
|
-
validator.
|
36
|
-
|
37
|
-
|
36
|
+
expect(validator).to receive(:sleep).exactly(2).times
|
37
|
+
|
38
|
+
expect {
|
38
39
|
validator.validate_html("dummy")
|
39
|
-
}.
|
40
|
+
}.to raise_exception(StandardError)
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
metadata
CHANGED
@@ -1,49 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: w3c_rspec_validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Dominik Goltermann
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2018-12-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: w3c_validators
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: rspec
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: rails
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - ">="
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '0'
|
44
48
|
type: :runtime
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
description: Allows testing vor valid html (including html5) and css. In addition
|
48
56
|
you can configure the gem to use a locally installed validation service instead
|
49
57
|
of the online w3c servers
|
@@ -53,7 +61,7 @@ executables: []
|
|
53
61
|
extensions: []
|
54
62
|
extra_rdoc_files: []
|
55
63
|
files:
|
56
|
-
- .gitignore
|
64
|
+
- ".gitignore"
|
57
65
|
- Gemfile
|
58
66
|
- README.md
|
59
67
|
- Rakefile
|
@@ -75,27 +83,25 @@ files:
|
|
75
83
|
- w3c_rspec_validators.gemspec
|
76
84
|
homepage: ''
|
77
85
|
licenses: []
|
86
|
+
metadata: {}
|
78
87
|
post_install_message:
|
79
88
|
rdoc_options: []
|
80
89
|
require_paths:
|
81
90
|
- lib
|
82
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
-
none: false
|
84
92
|
requirements:
|
85
|
-
- -
|
93
|
+
- - ">="
|
86
94
|
- !ruby/object:Gem::Version
|
87
95
|
version: '0'
|
88
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
97
|
requirements:
|
91
|
-
- -
|
98
|
+
- - ">="
|
92
99
|
- !ruby/object:Gem::Version
|
93
100
|
version: '0'
|
94
101
|
requirements: []
|
95
102
|
rubyforge_project: w3c_rspec_validators
|
96
|
-
rubygems_version:
|
103
|
+
rubygems_version: 2.7.6
|
97
104
|
signing_key:
|
98
|
-
specification_version:
|
105
|
+
specification_version: 4
|
99
106
|
summary: This gem adds w3c validation in form of rspec matchers
|
100
107
|
test_files: []
|
101
|
-
has_rdoc:
|