headhunter 0.0.2 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +50 -0
- data/README.md +84 -0
- data/Rakefile +7 -0
- data/lib/headhunter.rb +1 -51
- data/lib/headhunter/css_hunter.rb +1 -3
- data/lib/headhunter/css_validator.rb +1 -3
- data/lib/headhunter/html_validator.rb +1 -1
- data/lib/headhunter/rails.rb +2 -2
- data/lib/headhunter/runner.rb +51 -0
- data/lib/headhunter/version.rb +3 -0
- metadata +21 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e083d2cf2ed28ecd66e9fd0b7317c39565f996c
|
4
|
+
data.tar.gz: 874442a4314a680b9582be26ff1ac475590b3079
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ba8f645a5d4843b2e9e5df932dfe68cc91e2383e0cceb71c85b2c857c0b622e0f476957cadf321614c5302532f764f71056b7e0f6d45b7c2934af15a30c9282
|
7
|
+
data.tar.gz: 7a4e13c8f0df5a84980e24d6ccfe1bd1333152cbbf66b8e754349be72d12a3732d22f6f4b44a31d276e645babef849e00e4eac37c8bde4bb5fd1fb9dd0f8cca2
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
headhunter (0.0.2)
|
5
|
+
colorize
|
6
|
+
css_parser (~> 1.2.6)
|
7
|
+
html_validation
|
8
|
+
nokogiri
|
9
|
+
rspec
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
addressable (2.3.5)
|
15
|
+
colorize (0.6.0)
|
16
|
+
css_parser (1.2.6)
|
17
|
+
addressable
|
18
|
+
rdoc
|
19
|
+
diff-lcs (1.2.5)
|
20
|
+
fuubar (1.3.2)
|
21
|
+
rspec (>= 2.14.0, < 3.1.0)
|
22
|
+
ruby-progressbar (~> 1.3)
|
23
|
+
gem-release (0.7.1)
|
24
|
+
html_validation (1.0.0)
|
25
|
+
json (1.8.1)
|
26
|
+
mini_portile (0.5.2)
|
27
|
+
nokogiri (1.6.1)
|
28
|
+
mini_portile (~> 0.5.0)
|
29
|
+
rake (10.1.1)
|
30
|
+
rdoc (4.1.1)
|
31
|
+
json (~> 1.4)
|
32
|
+
rspec (2.14.1)
|
33
|
+
rspec-core (~> 2.14.0)
|
34
|
+
rspec-expectations (~> 2.14.0)
|
35
|
+
rspec-mocks (~> 2.14.0)
|
36
|
+
rspec-core (2.14.7)
|
37
|
+
rspec-expectations (2.14.4)
|
38
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
39
|
+
rspec-mocks (2.14.4)
|
40
|
+
ruby-progressbar (1.4.0)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
fuubar
|
47
|
+
gem-release
|
48
|
+
headhunter!
|
49
|
+
rake
|
50
|
+
rspec (>= 2.0)
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Headhunter
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/headhunter.png)](http://badge.fury.io/rb/headhunter)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/jmuheim/headhunter.png)](https://codeclimate.com/github/jmuheim/headhunter)
|
5
|
+
[![Travis CI](https://api.travis-ci.org/jmuheim/headhunter.png)](https://travis-ci.org/jmuheim/headhunter)
|
6
|
+
|
7
|
+
Headhunter is an HTML and CSS validation tool that injects itself into your Rails feature tests and automagically checks all your generated HTML and CSS for validity.
|
8
|
+
|
9
|
+
In addition, it also looks out for unused (and therefore superfluous) CSS selectors.
|
10
|
+
|
11
|
+
## How to use
|
12
|
+
|
13
|
+
Add Headhunter to your `Gemfile`:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
group :test do
|
17
|
+
gem 'headhunter'
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
Just set the environment variable `HEADHUNTER` to `true` when running your tests, e.g.:
|
22
|
+
|
23
|
+
- `rake HEADHUNTER=true`
|
24
|
+
- `rspec HEADHUNTER=true`
|
25
|
+
- `cucumber HEADHUNTER=true`
|
26
|
+
|
27
|
+
Headhunter doesn't keep your tests from passing if invalid HTML or unused CSS is found. Instead it displays a short statistic after the tests are run.
|
28
|
+
|
29
|
+
30/30 |============================= 100 ==============================>| Time: 00:00:02
|
30
|
+
|
31
|
+
Finished in 2.65 seconds
|
32
|
+
30 examples, 0 failures
|
33
|
+
|
34
|
+
Validated 42 HTML pages.
|
35
|
+
41 pages are valid.
|
36
|
+
1 page is invalid.
|
37
|
+
Open .validation/results.html to view full results.
|
38
|
+
|
39
|
+
Validated 1 stylesheets.
|
40
|
+
1 stylesheet is invalid.
|
41
|
+
application.css:
|
42
|
+
- Invalid css: line 1: Property bla doesn't exist
|
43
|
+
|
44
|
+
Found 23 CSS selectors.
|
45
|
+
20 selectors are in use.
|
46
|
+
3 selectors are not in use: a img, #flash.failure, input[type='file']
|
47
|
+
|
48
|
+
## How it works
|
49
|
+
|
50
|
+
Headhunter registers itself as middleware in the Rack stack and triggers validation for every HTML response.
|
51
|
+
|
52
|
+
For every `.css` file, validation is also triggered. In addition, it iterates over every HTML page's selectors to see whether there exist any unused CSS definitions in your `.css` files.
|
53
|
+
|
54
|
+
For being able to validate CSS, `rake assets:precompile` is triggered at the beginning of running tests. This may slow down starting your tests a bit. (Notice: after the tests have finished, the precompiled assets are also removed automatically by running `rake assets:clobber`.)
|
55
|
+
|
56
|
+
## Requirements
|
57
|
+
|
58
|
+
### Tidy HTML
|
59
|
+
|
60
|
+
[Tidy HTML](http://tidy.sourceforge.net/) should be installed on a typical OSX and Linux installation already. You're not developing on a Windows machine, are you?!
|
61
|
+
|
62
|
+
If you want to validate HTML5 (and you should want to!), install the HTML5 version like described here: [homebrew tidy html5](http://techblog.willshouse.com/2013/10/21/homebrew-tidy-html5/).
|
63
|
+
|
64
|
+
### Working internet connection
|
65
|
+
|
66
|
+
You need a working internet connection to run CSS validation. As a Rails application typically contains one single CSS file (`application.css`), this won't have much impact on the speed of your tests.
|
67
|
+
|
68
|
+
## Known issues and future plans
|
69
|
+
|
70
|
+
- It would be nice to use Rails' own assets compilation that's executed when the first JavaScript test is run. Anyone has an idea on how to do this?
|
71
|
+
- At the moment, in addition to precompiling and removing your assets, `rake assets:clobber` is run also **before** precompiling! The issue is explained here: [Rake assets are generated twice when precompiling them once from command line and once from within a Ruby script](http://stackoverflow.com/questions/20938891/rake-assets-are-generated-twice-when-precompiling-them-once-from-command-line-an)
|
72
|
+
- Instead of running `rake assets:clobber`, it may be also sufficient to simply remove all *.css files from `public/assets/stylesheets` manually. This would save some compilation time.
|
73
|
+
- Instead of using the online CSS validation service of ???, it would be nice to have a local CSS validator. Is there anything like this? TotalValidator seems to be able to do something like this, but it's not free for CSS validation and I don't know how to use it.
|
74
|
+
- HTML and CSS sources should not be compressed, to allow more concise error messages
|
75
|
+
- Would be really useful to have the concrete URL of every validated HTML page. But can't find a way to extract it from Rack response.
|
76
|
+
- There are not tests yet. I first want to see whether this gem would be appreciated by the community, and if so, I will definitely add tests.
|
77
|
+
|
78
|
+
## Disclaimer
|
79
|
+
|
80
|
+
Headhunter is heavily inspired by Aanand Prasad's (outdated) [Deadweight](https://github.com/aanand/deadweight) gem and by Unboxed Consulting's [be_valid_asset](https://github.com/unboxed/be_valid_asset) gem. Thank you for your pioneering work!
|
81
|
+
|
82
|
+
**USE THIS GEM AT YOUR OWN RISK!**
|
83
|
+
|
84
|
+
All provided functionality is provided "as is". You are highly welcome to file issues, feature requests and pull requests.
|
data/Rakefile
ADDED
data/lib/headhunter.rb
CHANGED
@@ -2,54 +2,4 @@ require 'headhunter/css_hunter'
|
|
2
2
|
require 'headhunter/css_validator'
|
3
3
|
require 'headhunter/html_validator'
|
4
4
|
require 'headhunter/rails'
|
5
|
-
|
6
|
-
|
7
|
-
class Headhunter
|
8
|
-
attr_accessor :results
|
9
|
-
|
10
|
-
def initialize(root)
|
11
|
-
@root = root
|
12
|
-
|
13
|
-
precompile_assets!
|
14
|
-
|
15
|
-
@html_validator = HtmlValidator.new
|
16
|
-
@css_validator = CssValidator.new(stylesheets)
|
17
|
-
@css_hunter = CssHunter.new(stylesheets)
|
18
|
-
|
19
|
-
@css_validator.process!
|
20
|
-
end
|
21
|
-
|
22
|
-
def process!(url, html)
|
23
|
-
@html_validator.process!(url, html)
|
24
|
-
@css_hunter.process!(url, html)
|
25
|
-
end
|
26
|
-
|
27
|
-
def clean_up!
|
28
|
-
remove_assets!
|
29
|
-
end
|
30
|
-
|
31
|
-
def report
|
32
|
-
@html_validator.prepare_results_html
|
33
|
-
|
34
|
-
@html_validator.report
|
35
|
-
@css_validator.report
|
36
|
-
@css_hunter.report
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def precompile_assets!
|
42
|
-
# Remove existing assets! This seems to be necessary to make sure that they don't exist twice, see http://stackoverflow.com/questions/20938891
|
43
|
-
system 'rake assets:clobber HEADHUNTER=false &> /dev/null'
|
44
|
-
|
45
|
-
system 'rake assets:precompile HEADHUNTER=false &> /dev/null'
|
46
|
-
end
|
47
|
-
|
48
|
-
def remove_assets!
|
49
|
-
system 'rake assets:clobber HEADHUNTER=false &> /dev/null'
|
50
|
-
end
|
51
|
-
|
52
|
-
def stylesheets
|
53
|
-
Dir.chdir(@root) { Dir.glob('public/assets/*.css') }
|
54
|
-
end
|
55
|
-
end
|
5
|
+
require 'headhunter/runner'
|
@@ -2,7 +2,7 @@ require 'css_parser'
|
|
2
2
|
require 'nokogiri'
|
3
3
|
require 'open-uri'
|
4
4
|
|
5
|
-
|
5
|
+
module Headhunter
|
6
6
|
class CssHunter
|
7
7
|
def initialize(stylesheets)
|
8
8
|
@stylesheets = stylesheets
|
@@ -52,8 +52,6 @@ class Headhunter
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def fetch(path)
|
55
|
-
log.puts(path)
|
56
|
-
|
57
55
|
loc = path
|
58
56
|
|
59
57
|
begin
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'rexml/document'
|
3
3
|
|
4
|
-
|
4
|
+
module Headhunter
|
5
5
|
class CssValidator
|
6
6
|
def initialize(stylesheets)
|
7
7
|
@profile = 'css3' # TODO: Option for profile css1 and css21
|
@@ -58,8 +58,6 @@ class Headhunter
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def fetch(path) # TODO: Move to Headhunter!
|
61
|
-
log.puts(path)
|
62
|
-
|
63
61
|
loc = path
|
64
62
|
|
65
63
|
begin
|
data/lib/headhunter/rails.rb
CHANGED
@@ -2,11 +2,11 @@ require 'headhunter'
|
|
2
2
|
require 'headhunter/rack/capturing_middleware'
|
3
3
|
|
4
4
|
if ENV['HEADHUNTER'] == 'true'
|
5
|
-
|
5
|
+
module Headhunter
|
6
6
|
module Rails
|
7
7
|
class Railtie < ::Rails::Railtie
|
8
8
|
initializer "headhunter.hijack" do |app|
|
9
|
-
head_hunter =
|
9
|
+
head_hunter = Runner.new(::Rails.root)
|
10
10
|
|
11
11
|
at_exit do
|
12
12
|
head_hunter.report
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Headhunter
|
2
|
+
class Runner
|
3
|
+
attr_accessor :results
|
4
|
+
|
5
|
+
def initialize(root)
|
6
|
+
@root = root
|
7
|
+
|
8
|
+
precompile_assets!
|
9
|
+
|
10
|
+
@html_validator = HtmlValidator.new
|
11
|
+
@css_validator = CssValidator.new(stylesheets)
|
12
|
+
@css_hunter = CssHunter.new(stylesheets)
|
13
|
+
|
14
|
+
@css_validator.process!
|
15
|
+
end
|
16
|
+
|
17
|
+
def process!(url, html)
|
18
|
+
@html_validator.process!(url, html)
|
19
|
+
@css_hunter.process!(url, html)
|
20
|
+
end
|
21
|
+
|
22
|
+
def clean_up!
|
23
|
+
remove_assets!
|
24
|
+
end
|
25
|
+
|
26
|
+
def report
|
27
|
+
@html_validator.prepare_results_html
|
28
|
+
|
29
|
+
@html_validator.report
|
30
|
+
@css_validator.report
|
31
|
+
@css_hunter.report
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def precompile_assets!
|
37
|
+
# Remove existing assets! This seems to be necessary to make sure that they don't exist twice, see http://stackoverflow.com/questions/20938891
|
38
|
+
system 'rake assets:clobber HEADHUNTER=false &> /dev/null'
|
39
|
+
|
40
|
+
system 'rake assets:precompile HEADHUNTER=false &> /dev/null'
|
41
|
+
end
|
42
|
+
|
43
|
+
def remove_assets!
|
44
|
+
system 'rake assets:clobber HEADHUNTER=false &> /dev/null'
|
45
|
+
end
|
46
|
+
|
47
|
+
def stylesheets
|
48
|
+
Dir.chdir(@root) { Dir.glob('public/assets/*.css') }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: headhunter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Muheim
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: gem-release
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: rake
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,9 +150,15 @@ files:
|
|
136
150
|
- lib/headhunter/html_validator.rb
|
137
151
|
- lib/headhunter/rack/capturing_middleware.rb
|
138
152
|
- lib/headhunter/rails.rb
|
153
|
+
- lib/headhunter/runner.rb
|
139
154
|
- lib/headhunter/templates/result.html
|
140
155
|
- lib/headhunter/templates/results.html
|
156
|
+
- lib/headhunter/version.rb
|
141
157
|
- lib/headhunter.rb
|
158
|
+
- Gemfile
|
159
|
+
- Gemfile.lock
|
160
|
+
- Rakefile
|
161
|
+
- README.md
|
142
162
|
homepage: http://github.com/jmuheim/headhunter
|
143
163
|
licenses:
|
144
164
|
- MIT
|