Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring and bug fixing #14

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--color
196 changes: 78 additions & 118 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,43 @@ PATH
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.0.4)
actionpack (= 4.0.4)
actionmailer (4.1.4)
actionpack (= 4.1.4)
actionview (= 4.1.4)
mail (~> 2.5.4)
actionpack (4.0.4)
activesupport (= 4.0.4)
builder (~> 3.1.0)
erubis (~> 2.7.0)
actionpack (4.1.4)
actionview (= 4.1.4)
activesupport (= 4.1.4)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
activemodel (4.0.4)
activesupport (= 4.0.4)
builder (~> 3.1.0)
activerecord (4.0.4)
activemodel (= 4.0.4)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.4)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.4)
actionview (4.1.4)
activesupport (= 4.1.4)
builder (~> 3.1)
erubis (~> 2.7.0)
activemodel (4.1.4)
activesupport (= 4.1.4)
builder (~> 3.1)
activerecord (4.1.4)
activemodel (= 4.1.4)
activesupport (= 4.1.4)
arel (~> 5.0.0)
activesupport (4.1.4)
i18n (~> 0.6, >= 0.6.9)
minitest (~> 4.2)
multi_json (~> 1.3)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
addressable (2.3.5)
arel (4.0.2)
atomic (1.1.16)
awesome_print (1.2.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.1.4)
capybara (2.2.1)
tzinfo (~> 1.1)
addressable (2.3.6)
arel (5.0.1.20140414130214)
builder (3.2.2)
capybara (2.4.1)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
coderay (1.1.0)
colorize (0.7.0)
columnize (0.3.6)
coolline (0.4.3)
colorize (0.7.3)
coveralls (0.7.0)
multi_json (~> 1.3)
rest-client
Expand All @@ -59,130 +55,94 @@ GEM
thor
css_parser (1.3.5)
addressable
debug_inspector (0.0.2)
debugger (1.6.6)
columnize (>= 0.3.1)
debugger-linecache (~> 1.2.0)
debugger-ruby_core_source (~> 1.3.2)
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.3.2)
diff-lcs (1.2.5)
diffy (3.0.3)
docile (1.1.3)
docile (1.1.5)
erubis (2.7.0)
grit (2.5.0)
diff-lcs (~> 1.1)
mime-types (~> 1.15)
posix-spawn (~> 0.3.6)
hike (1.2.3)
hirb (0.7.1)
i18n (0.6.9)
jazz_hands (0.5.2)
awesome_print (~> 1.2)
coolline (>= 0.4.2)
hirb (~> 0.7.1)
pry (~> 0.9.12)
pry-debugger (~> 0.2.2)
pry-doc (~> 0.4.6)
pry-git (~> 0.2.3)
pry-rails (~> 0.3.2)
pry-remote (>= 0.1.7)
pry-stack_explorer (~> 0.4.9)
railties (>= 3.0, < 5.0)
i18n (0.6.11)
json (1.8.1)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.8.2)
mime-types (1.25.1)
mini_portile (0.5.2)
minitest (4.7.5)
multi_json (1.9.0)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
polyglot (0.3.4)
posix-spawn (0.3.8)
pry (0.9.12.6)
coderay (~> 1.0)
method_source (~> 0.8)
mini_portile (0.6.0)
minitest (5.4.0)
multi_json (1.10.1)
netrc (0.7.7)
nokogiri (1.6.3)
mini_portile (= 0.6.0)
polyglot (0.3.5)
pry (0.10.0)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-debugger (0.2.2)
debugger (~> 1.3)
pry (~> 0.9.10)
pry-doc (0.4.6)
pry (>= 0.9)
yard (>= 0.8)
pry-git (0.2.3)
diffy
grit
pry (>= 0.9.8)
pry-rails (0.3.2)
pry (>= 0.9.10)
pry-remote (0.1.8)
pry (~> 0.9)
slop (~> 3.0)
pry-stack_explorer (0.4.9.1)
binding_of_caller (>= 0.7)
pry (>= 0.9.11)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
rails (4.0.4)
actionmailer (= 4.0.4)
actionpack (= 4.0.4)
activerecord (= 4.0.4)
activesupport (= 4.0.4)
rails (4.1.4)
actionmailer (= 4.1.4)
actionpack (= 4.1.4)
actionview (= 4.1.4)
activemodel (= 4.1.4)
activerecord (= 4.1.4)
activesupport (= 4.1.4)
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.4)
sprockets-rails (~> 2.0.0)
railties (4.0.4)
actionpack (= 4.0.4)
activesupport (= 4.0.4)
railties (= 4.1.4)
sprockets-rails (~> 2.0)
railties (4.1.4)
actionpack (= 4.1.4)
activesupport (= 4.1.4)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.1.1)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
rspec-rails (2.14.1)
rake (10.3.2)
rest-client (1.7.2)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rspec-core (3.0.2)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec-mocks (3.0.2)
rspec-support (~> 3.0.0)
rspec-rails (3.0.1)
actionpack (>= 3.0)
activemodel (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
simplecov (0.8.2)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-support (~> 3.0.0)
rspec-support (3.0.2)
simplecov (0.9.0)
docile (~> 1.1.0)
multi_json
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
slop (3.5.0)
sprockets (2.12.0)
slop (3.6.0)
sprockets (2.12.1)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.0.1)
sprockets-rails (2.1.3)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
term-ansicolor (1.3.0)
tins (~> 1.0)
thor (0.18.1)
thread_safe (0.2.0)
atomic (>= 1.1.7, < 2)
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
tins (1.0.1)
tins (1.3.0)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.39)
tzinfo (1.2.1)
thread_safe (~> 0.1)
xpath (2.0.0)
nokogiri (~> 1.3)
yard (0.8.7.3)

PLATFORMS
ruby
Expand All @@ -191,5 +151,5 @@ DEPENDENCIES
capybara
coveralls
headhunter!
jazz_hands
pry
rspec-rails
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ $ HEADHUNTER=true cucumber

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.

If you want to disable a single part of validation, start your tests with this environment variables:

```
$ HEADHUNTER=true HEADHUNTER_CSS=false rspec # only HTML stuff is invoked
$ HEADHUNTER=true HEADHUNTER_HTML=false rspec # only CSS stuff is invoked
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer it the following way:

$ HEADHUNTER_HTML=true rspec # only HTML stuff is invoked
$ HEADHUNTER_CSS=true rspec # only CSS stuff is invoked

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I was not sure If I should break the default options.

```

![Headhunter output](docs/screenshot.png)

## How it works
Expand Down
2 changes: 1 addition & 1 deletion headhunter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Gem::Specification.new do |s|
s.add_dependency 'colorize'
s.add_dependency 'nokogiri'

s.add_development_dependency 'pry'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'capybara'
s.add_development_dependency 'jazz_hands'

s.test_files = Dir['spec/**/*']
end
6 changes: 4 additions & 2 deletions lib/headhunter.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
if ENV['HEADHUNTER'] == 'true'
if ENV['HEADHUNTER'] == 'true' || ENV['RAILS_ENV'] == 'test'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this was added, but it causes an infinite loop. I have to remove it to use this branch.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to investigate this myself. It's a long time ago already...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

infinite loop? Could you show me your command you ran?
I'm not sure anymore, but I suppose I did not get one. I'll try again.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it didn't matter what command I ran, it hung on precompiling assets which makes sense since this enables headhunter in all test environments regardless of whether or not you wanted to enable headhunter which would cause the assets to get precompiled (i'm guessing here, but that seems to be what happened)

require 'headhunter/engine'
require 'headhunter/css_hunter'
require 'headhunter/css_validator'
require 'headhunter/html_validator'
require 'headhunter/rails'
require 'headhunter/runner'
require 'headhunter/runners/runner'
require 'headhunter/runners/html_runner'
require 'headhunter/runners/css_runner'
end

module Headhunter
Expand Down
2 changes: 1 addition & 1 deletion lib/headhunter/css_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(stylesheets = [], profile = 'css3', vextwarning = true)

def validate(uri)
Dir.chdir(VALIDATOR_DIR) do
raise "Couldn't locate uri #{uri}" unless File.exists? uri
fail "Couldn't locate uri #{uri}" unless File.exists? uri

# See http://stackoverflow.com/questions/1137884/is-there-an-open-source-css-validator-that-can-be-run-locally
# More config options see http://jigsaw.w3.org/css-validator/manual.html
Expand Down
33 changes: 25 additions & 8 deletions lib/headhunter/html_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,34 @@ def initialize
end

def validate(uri, html)
Dir.chdir(VALIDATOR_DIR) do
raise "Could not find tidy in #{Dir.pwd}" unless File.exists? EXECUTABLE
executable = %x[which #{EXECUTABLE}]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%x-literals should be delimited by ( and )
Do not use %x unless the command string contains backquotes.

if executable.present?
path = File.dirname(executable).strip
executable = File.basename(executable).strip
else
path = VALIDATOR_DIR
executable = EXECUTABLE
end

Dir.chdir(path) do
fail "Could not find #{executable} in #{Dir.pwd}" unless File.exists? executable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [88/80]


# tidy_version = `#{executable} -v`
# puts "Using #{executable}: #{tidy_version}"

# Docs for Tidy: http://tidy.sourceforge.net/docs/quickref.html
stdin, stdout, stderr = Open3.popen3("#{EXECUTABLE} -quiet")
stdin.puts html
stdin.close
stdout.close

@responses << Response.new(stderr.read, uri)
stderr.close
begin
stdin, stdout, stderr = Open3.popen3("#{executable} -quiet")
stdin.puts html
stdin.close
stdout.close

@responses << Response.new(stderr.read, uri)
stderr.close
rescue Encoding::UndefinedConversionError
# not HTML, maybe something else (PDF, image, ...)
end
end
end

Expand Down
9 changes: 5 additions & 4 deletions lib/headhunter/rack/capturing_middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ def initialize(app, headhunter)
end

def call(env)
url = env['PATH_INFO'] || 'unknown'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I didn't find out where to get this from! 👍

response = @app.call(env)
process(response)
process(url, response)
response
end

def process(rack_response)
def process(url, rack_response)
status, headers, response = rack_response

if html = extract_html_from(response)
@hh.process('unknown', html)
@hh.process(url, html)
end
end

def extract_html_from(response)
response[0]
response[0] if response.respond_to? :[]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I hit this bug, this is necessary

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain this a bit better?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a bug for a specific middleware request which triggered it, if it is not array-ish.
So this only takes the first element if it really is an array-like object.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall exactly what it was, but they were sprockets assets that were returning. This should really check to make sure the thing is actually html I'd think. response header content type?

end
end
end
Expand Down
Loading