headhunter 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +28 -3
- data/lib/headhunter.rb +11 -5
- data/lib/headhunter/css_hunter.rb +4 -3
- data/lib/headhunter/css_validator.rb +21 -15
- data/lib/headhunter/engine.rb +11 -0
- data/lib/headhunter/html_validator.rb +8 -6
- data/lib/headhunter/rails.rb +10 -12
- data/lib/headhunter/runner.rb +1 -1
- data/lib/headhunter/version.rb +1 -1
- data/lib/tasks/headhunter_tasks.rake +4 -0
- data/lib/tidy/{tidy → tidy2} +0 -0
- data/spec/dummy/Gemfile +9 -0
- data/spec/dummy/Gemfile.lock +178 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +13 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/posts_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/posts/index.html.erb +21 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +26 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/log/development.log +247 -0
- data/spec/dummy/log/test.log +452 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/features/bla_spec.rb +9 -0
- data/spec/dummy/spec/spec_helper.rb +16 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1e8f75a6b5b33970fb8e397347caa0a1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/24204f742af588c8166d3160b500d20f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/416150dc3ac35079c94273cc46e90aa6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/510da110ae528e2d22533be39ff696c5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5384ad85f52d3272dbc64d46ef3876a4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c85016e7bbd4f3adbb7635d01f85d39b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d066c004d1fd26ae76a61303a7a18145 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/416150dc3ac35079c94273cc46e90aa6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/5384ad85f52d3272dbc64d46ef3876a4 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/c85016e7bbd4f3adbb7635d01f85d39b +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/d066c004d1fd26ae76a61303a7a18145 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/files/css_hunter/valid.html +15 -0
- data/spec/files/css_validator/invalid.css +42 -0
- data/spec/files/css_validator/invalid_response.xml +40 -0
- data/spec/files/css_validator/valid.css +39 -0
- data/spec/files/css_validator/valid_response.xml +23 -0
- data/spec/files/html_validator/invalid.html +15 -0
- data/spec/files/html_validator/invalid_response.txt +1 -0
- data/spec/files/html_validator/valid.html +15 -0
- data/spec/files/html_validator/valid_response.txt +0 -0
- data/spec/files/html_with_srcset.html +14 -0
- data/spec/files/html_without_srcset.html +14 -0
- data/spec/files/invalid2.html +16 -0
- data/spec/files/valid-1.css +31 -0
- data/spec/files/valid-2.css +42 -0
- data/spec/files/valid-3.css +48 -0
- data/spec/files/valid.html5 +14 -0
- data/spec/files/valid_with_cache_busters.html +16 -0
- data/spec/files/valid_without_cache_busters.html +16 -0
- data/spec/lib/headhunter/css_hunter_spec.rb +83 -0
- data/spec/lib/headhunter/css_validator_spec.rb +196 -0
- data/spec/lib/headhunter/html_validator_spec.rb +143 -0
- data/spec/spec_helper.rb +25 -0
- metadata +193 -86
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -78
- data/README.md +0 -78
- data/docs/headhunter.png +0 -0
- data/docs/money.png +0 -0
- data/docs/screenshot.png +0 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2
|
+
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
6
|
+
<title>Test Valid Page</title>
|
7
|
+
</head>
|
8
|
+
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<h1>Test#valid</h1>
|
12
|
+
<p>This is an example valid html file</p>
|
13
|
+
|
14
|
+
</body>
|
15
|
+
</html>
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
5
|
+
<title>Test Valid Page</title>
|
6
|
+
</head>
|
7
|
+
|
8
|
+
<body>
|
9
|
+
|
10
|
+
<h1>Test#valid</h1>
|
11
|
+
<img src="/images/test.jpg" alt="test" srcset="/images/test.jpg">
|
12
|
+
<br>
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
5
|
+
<title>Test Valid Page</title>
|
6
|
+
</head>
|
7
|
+
|
8
|
+
<body>
|
9
|
+
|
10
|
+
<h1>Test#valid</h1>
|
11
|
+
<img src="/images/test.jpg" alt="test">
|
12
|
+
<br>
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2
|
+
|
3
|
+
<p>This isn't valid here</p>
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
7
|
+
<title>Test Invalid Page</title>
|
8
|
+
</head>
|
9
|
+
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<h1>Test#invalid</h1>
|
13
|
+
<p><b>This is an example invalid html file</b></p>
|
14
|
+
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
html, body
|
2
|
+
{
|
3
|
+
background:#007086;
|
4
|
+
font-family:Arial,Helvetica,sans-serif;
|
5
|
+
font-size:0.83em;
|
6
|
+
margin:0;
|
7
|
+
padding:0;
|
8
|
+
}
|
9
|
+
ul, ul li
|
10
|
+
{
|
11
|
+
list-style-type: none;
|
12
|
+
}
|
13
|
+
.hidden
|
14
|
+
{
|
15
|
+
display: none;
|
16
|
+
}
|
17
|
+
a img
|
18
|
+
{
|
19
|
+
border: none;
|
20
|
+
}
|
21
|
+
a
|
22
|
+
{
|
23
|
+
text-decoration: none;
|
24
|
+
}
|
25
|
+
.clear-float
|
26
|
+
{
|
27
|
+
clear: both;
|
28
|
+
font-size: 1px;
|
29
|
+
height: 0px;
|
30
|
+
line-height: 0px;
|
31
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
html, body
|
2
|
+
{
|
3
|
+
background:#007086;
|
4
|
+
font-family:Arial,Helvetica,sans-serif;
|
5
|
+
font-size:0.83em;
|
6
|
+
margin:0;
|
7
|
+
padding:0;
|
8
|
+
}
|
9
|
+
|
10
|
+
*
|
11
|
+
{
|
12
|
+
margin:0;
|
13
|
+
padding:0;
|
14
|
+
}
|
15
|
+
ul, ul li
|
16
|
+
{
|
17
|
+
list-style-type: none;
|
18
|
+
}
|
19
|
+
|
20
|
+
.hidden
|
21
|
+
{
|
22
|
+
display: none;
|
23
|
+
}
|
24
|
+
a img
|
25
|
+
{
|
26
|
+
border: none;
|
27
|
+
}
|
28
|
+
a
|
29
|
+
{
|
30
|
+
text-decoration: none;
|
31
|
+
}
|
32
|
+
a:hover
|
33
|
+
{
|
34
|
+
text-decoration: underline;
|
35
|
+
}
|
36
|
+
.clear-float
|
37
|
+
{
|
38
|
+
clear: both;
|
39
|
+
font-size: 1px;
|
40
|
+
height: 0px;
|
41
|
+
line-height: 0px;
|
42
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
html, body
|
2
|
+
{
|
3
|
+
background:#007086;
|
4
|
+
font-family:Arial,Helvetica,sans-serif;
|
5
|
+
font-size:0.83em;
|
6
|
+
margin:0;
|
7
|
+
padding:0;
|
8
|
+
}
|
9
|
+
|
10
|
+
*
|
11
|
+
{
|
12
|
+
margin:0;
|
13
|
+
padding:0;
|
14
|
+
}
|
15
|
+
ul, ul li
|
16
|
+
{
|
17
|
+
list-style-type: none;
|
18
|
+
}
|
19
|
+
li:last-child {
|
20
|
+
padding-bottom: 0.2em;
|
21
|
+
}
|
22
|
+
.hidden
|
23
|
+
{
|
24
|
+
display: none;
|
25
|
+
}
|
26
|
+
a img
|
27
|
+
{
|
28
|
+
border: none;
|
29
|
+
}
|
30
|
+
a
|
31
|
+
{
|
32
|
+
text-decoration: none;
|
33
|
+
}
|
34
|
+
a[href^="ftp"]
|
35
|
+
{
|
36
|
+
text-decoration: underline;
|
37
|
+
}
|
38
|
+
a:hover
|
39
|
+
{
|
40
|
+
text-decoration: underline;
|
41
|
+
}
|
42
|
+
.clear-float
|
43
|
+
{
|
44
|
+
clear: both;
|
45
|
+
font-size: 1px;
|
46
|
+
height: 0px;
|
47
|
+
line-height: 0px;
|
48
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
5
|
+
<title>Test Valid Page</title>
|
6
|
+
</head>
|
7
|
+
|
8
|
+
<body>
|
9
|
+
|
10
|
+
<h1>Test#valid</h1>
|
11
|
+
<p>This is an example valid html5 file</p>
|
12
|
+
<br>
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
5
|
+
<title>Test Valid Page</title>
|
6
|
+
</head>
|
7
|
+
|
8
|
+
<body>
|
9
|
+
|
10
|
+
<h1>Test#valid</h1>
|
11
|
+
<p>This is an example valid html5 file</p>
|
12
|
+
<a href="/testing?655557777">Test link</a>
|
13
|
+
<img src="/images/test.jpg?123456" alt="test">
|
14
|
+
<br>
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
5
|
+
<title>Test Valid Page</title>
|
6
|
+
</head>
|
7
|
+
|
8
|
+
<body>
|
9
|
+
|
10
|
+
<h1>Test#valid</h1>
|
11
|
+
<p>This is an example valid html5 file</p>
|
12
|
+
<a href="/testing">Test link</a>
|
13
|
+
<img src="/images/test.jpg" alt="test">
|
14
|
+
<br>
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Headhunter
|
4
|
+
describe CssHunter do
|
5
|
+
describe '#remove_pseudo_classes_from' do
|
6
|
+
subject { described_class.new }
|
7
|
+
|
8
|
+
it 'returns pseudo classes' do
|
9
|
+
expect(subject.remove_pseudo_classes_from('textarea:not(.something)')).to eq 'textarea'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#bare_selector_from' do
|
14
|
+
subject { described_class.new }
|
15
|
+
|
16
|
+
it 'cleans a selector from stuff like pseudo classes' do
|
17
|
+
expect(subject.bare_selector_from('textarea:not(.something)')).to eq 'textarea'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#add_css_selectors_from' do
|
22
|
+
subject { described_class.new }
|
23
|
+
|
24
|
+
it 'adds selectors' do
|
25
|
+
subject.add_css_selectors_from(read_file('css_validator/valid.css'))
|
26
|
+
|
27
|
+
expect(subject.error_selectors).to eq []
|
28
|
+
expect(subject.used_selectors).to eq []
|
29
|
+
expect(subject.unused_selectors).to match_array ['html', 'body', '*', 'ul', 'ul li', '.hidden', 'a img', 'a',
|
30
|
+
'a:hover', '.clear-float']
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#detect_used_selectors_in' do
|
35
|
+
subject { described_class.new }
|
36
|
+
|
37
|
+
it 'adds selectors' do
|
38
|
+
subject.add_css_selectors_from(read_file('css_validator/valid.css'))
|
39
|
+
|
40
|
+
expect(subject.detect_used_selectors_in(read_file('css_hunter/valid.html'))).to match_array ['html', 'body', '*']
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'gracefully ignores invalid rules' do
|
44
|
+
pending "Don't know how to do this"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#process' do
|
49
|
+
subject { described_class.new }
|
50
|
+
|
51
|
+
it 'processes given html' do
|
52
|
+
subject.add_css_selectors_from(read_file('css_validator/valid.css'))
|
53
|
+
subject.process(read_file('css_hunter/valid.html'))
|
54
|
+
|
55
|
+
expect(subject.error_selectors).to eq []
|
56
|
+
expect(subject.used_selectors).to eq ['html', 'body', '*']
|
57
|
+
expect(subject.unused_selectors).to match_array ['ul', 'ul li', '.hidden', 'a img', 'a', 'a:hover',
|
58
|
+
'.clear-float']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#statistics' do
|
63
|
+
subject do
|
64
|
+
css_hunter = described_class.new
|
65
|
+
css_hunter.add_css_selectors_from(read_file('css_validator/valid.css'))
|
66
|
+
css_hunter.process(read_file('css_hunter/valid.html'))
|
67
|
+
css_hunter.statistics
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns a text with nice statistics" do
|
71
|
+
expect(subject).to match 'Found 10 CSS selectors.'
|
72
|
+
expect(subject).to match '7 selectors are not in use:'
|
73
|
+
expect(subject).to match '.clear-float'
|
74
|
+
expect(subject).to match '.hidden'
|
75
|
+
expect(subject).to match 'a'
|
76
|
+
expect(subject).to match 'a img'
|
77
|
+
expect(subject).to match 'a:hover'
|
78
|
+
expect(subject).to match 'ul'
|
79
|
+
expect(subject).to match 'ul li'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,196 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Headhunter::CssValidator do # TODO: "Module Headhunter"
|
4
|
+
describe '#validate' do
|
5
|
+
subject { described_class.new }
|
6
|
+
|
7
|
+
it 'adds a response when calling the validator succeeds' do
|
8
|
+
expect {
|
9
|
+
subject.validate(path_to_file('css_validator/invalid.css'))
|
10
|
+
}.to change { subject.responses.count }.by 1
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'throws an exception when calling the validator fails'
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#extract_filename' do
|
17
|
+
subject { described_class.new }
|
18
|
+
|
19
|
+
it 'for a compiled asset, it returns the name of the file without the cache hash' do
|
20
|
+
filename = '/rails/root/public/assets/some-rails_asset-1f6355461e8ff118448a9649a392632c.css'
|
21
|
+
expect(subject.send(:extract_filename, filename)).to eq 'some-rails_asset.css'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'for any other file, it simply returns the name' do
|
25
|
+
filename = '/rails/root/public/assets/some_other-file.css'
|
26
|
+
expect(subject.send(:extract_filename, filename)).to eq 'some_other-file.css'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#x_stylesheets_be' do
|
31
|
+
subject { described_class.new }
|
32
|
+
|
33
|
+
it "creates a grammatically correct sentence when there is no stylesheet" do
|
34
|
+
expect(subject.x_stylesheets_be(0)).to eq '0 stylesheet is'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "creates a grammatically correct sentence when there is only one stylesheet" do
|
38
|
+
expect(subject.x_stylesheets_be(1)).to eq '1 stylesheet is'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "creates a grammatically correct sentence when there is more than one stylesheet" do
|
42
|
+
expect(subject.x_stylesheets_be(2)).to eq '2 stylesheets are'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#statistics' do
|
47
|
+
context 'for valid CSS' do
|
48
|
+
subject { described_class.new([path_to_file('css_validator/valid.css')]).statistics }
|
49
|
+
|
50
|
+
it "returns a text with nice statistics" do
|
51
|
+
expect(subject).to match 'Validated 1 stylesheet.'
|
52
|
+
expect(subject).to match 'All stylesheets are valid.'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'for invalid CSS' do
|
57
|
+
subject { described_class.new([path_to_file('css_validator/invalid.css')]).statistics }
|
58
|
+
|
59
|
+
it "returns a text with nice statistics" do
|
60
|
+
expect(subject).to match 'Validated 1 stylesheet.'
|
61
|
+
expect(subject).to match '1 stylesheet is invalid.'
|
62
|
+
expect(subject).to match 'invalid.css:'
|
63
|
+
expect(subject).to match "Line 8: Property wibble doesn't exist."
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#initialize' do
|
69
|
+
context 'for no CSS' do
|
70
|
+
subject { described_class.new }
|
71
|
+
|
72
|
+
it 'executes validation' do
|
73
|
+
expect(subject.valid_responses.size).to eq 0
|
74
|
+
expect(subject.invalid_responses.size).to eq 0
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'for valid CSS' do
|
79
|
+
subject { described_class.new([path_to_file('css_validator/valid.css')]) }
|
80
|
+
|
81
|
+
it 'executes validation' do
|
82
|
+
expect(subject.valid_responses.size).to eq 1
|
83
|
+
expect(subject.invalid_responses.size).to eq 0
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'for invalid CSS' do
|
88
|
+
subject { described_class.new([path_to_file('css_validator/invalid.css')]) }
|
89
|
+
|
90
|
+
it 'executes validation' do
|
91
|
+
expect(subject.invalid_responses.size).to eq 1
|
92
|
+
expect(subject.valid_responses.size).to eq 0
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#valid_responses' do
|
98
|
+
subject { described_class.new([path_to_file('css_validator/valid.css')]) }
|
99
|
+
|
100
|
+
it 'returns all valid responses' do
|
101
|
+
expect(subject.valid_responses.size).to eq 1
|
102
|
+
expect(subject.invalid_responses.size).to eq 0
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '#invalid_responses' do
|
107
|
+
subject { described_class.new([path_to_file('css_validator/invalid.css')]) }
|
108
|
+
|
109
|
+
it 'returns all valid responses' do
|
110
|
+
expect(subject.invalid_responses.size).to eq 1
|
111
|
+
expect(subject.valid_responses.size).to eq 0
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe Headhunter::CssValidator::Response do
|
117
|
+
describe '#initialize' do
|
118
|
+
context 'valid response' do
|
119
|
+
subject { described_class.new(read_file('css_validator/valid_response.xml')) }
|
120
|
+
|
121
|
+
it { should be_valid }
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'invalid response' do
|
125
|
+
subject { described_class.new(read_file('css_validator/invalid_response.xml')) }
|
126
|
+
|
127
|
+
it { should_not be_valid }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe '#errors' do
|
132
|
+
context 'valid response' do
|
133
|
+
subject { described_class.new(read_file('css_validator/valid_response.xml')) }
|
134
|
+
|
135
|
+
it 'returns an empty array' do
|
136
|
+
expect(subject.errors).to eq []
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'invalid response' do
|
141
|
+
subject { described_class.new(read_file('css_validator/invalid_response.xml')) }
|
142
|
+
|
143
|
+
it 'returns an array of errors' do
|
144
|
+
expect(subject.errors.size).to eq 1
|
145
|
+
expect(subject.errors.first).to be_a Headhunter::CssValidator::Response::Error
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe '#convert_soap_to_xml' do
|
151
|
+
subject { described_class.new }
|
152
|
+
|
153
|
+
it 'converts SOAP to XML' do
|
154
|
+
string = "this is the first line\n<m:errors><m:pipapo><bla>Bla!</bla</m:pipapo</m:errors>"
|
155
|
+
expect(subject.send :convert_soap_to_xml, string).to eq "<errors><pipapo><bla>Bla!</bla</pipapo</errors>"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe '#remove_first_line_from' do
|
160
|
+
subject { described_class.new }
|
161
|
+
|
162
|
+
it 'removes the first line from a passed string' do
|
163
|
+
string = "this is the first line\nthis\nis the\nrest"
|
164
|
+
expect(subject.send :remove_first_line_from, string).to eq "this\nis the\nrest"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe '#sanitize_prefixed_tags_from' do
|
169
|
+
subject { described_class.new }
|
170
|
+
|
171
|
+
it 'replaces tags like <m:error> with <error> in a passed string' do
|
172
|
+
string = "<m:errors><m:pipapo><bla>Bla!</bla</m:pipapo</m:errors>"
|
173
|
+
expect(subject.send :sanitize_prefixed_tags_from, string).to eq "<errors><pipapo><bla>Bla!</bla</pipapo</errors>"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe '#uri' do
|
178
|
+
subject { described_class.new(read_file('css_validator/valid_response.xml')) }
|
179
|
+
|
180
|
+
it "returns the validated uri's path" do
|
181
|
+
expect(subject.send :uri).to eq 'file:tmp.css'
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe Headhunter::CssValidator::Response::Error do
|
187
|
+
describe '#initialize' do
|
188
|
+
subject { described_class.new(123, "Attribute xyz doesn't exist", context: 'something', anything_else: 'bla') }
|
189
|
+
|
190
|
+
it 'assigns the passed params correctly' do
|
191
|
+
expect(subject.line).to eq 123
|
192
|
+
expect(subject.message).to eq "Attribute xyz doesn't exist"
|
193
|
+
expect(subject.details).to eq context: 'something', anything_else: 'bla'
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|