html_acceptance 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +24 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +72 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/html_acceptance.gemspec +69 -0
- data/lib/.rake +0 -0
- data/lib/html_acceptance/html_acceptance_result.rb +85 -0
- data/lib/html_acceptance.rb +56 -0
- data/lib/tasks/html_acceptance.rake +21 -0
- data/spec/html_acceptance_spec.rb +89 -0
- data/spec/spec_helper.rb +12 -0
- metadata +144 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.3.0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
# Unix Rubies (OSX, Linux)
|
17
|
+
platform :ruby do
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
# Windows Rubies (RubyInstaller)
|
22
|
+
platforms :mswin, :mingw do
|
23
|
+
|
24
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.5.2)
|
7
|
+
bundler (~> 1.0.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rake (0.8.7)
|
11
|
+
rcov (0.9.9)
|
12
|
+
rspec (2.3.0)
|
13
|
+
rspec-core (~> 2.3.0)
|
14
|
+
rspec-expectations (~> 2.3.0)
|
15
|
+
rspec-mocks (~> 2.3.0)
|
16
|
+
rspec-core (2.3.1)
|
17
|
+
rspec-expectations (2.3.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.3.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
bundler (~> 1.0.0)
|
26
|
+
jeweler (~> 1.5.2)
|
27
|
+
rcov
|
28
|
+
rspec (~> 2.3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Eric Beland
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
= HTML Acceptance
|
2
|
+
|
3
|
+
HTLM Acceptance helps you track, fix, and come to terms with your HTML's validity, or lack thereof.
|
4
|
+
The idea is to take an html markup string associated with a particular resource (file or URL),
|
5
|
+
and validate it. HTML Acceptance is intended to be used in acceptance tests, test suites or rake tasks
|
6
|
+
to alert you to changes in your html's validity so you can fix them, or barring that, review and accept
|
7
|
+
any errors and warnings.
|
8
|
+
|
9
|
+
|
10
|
+
== Usage:
|
11
|
+
|
12
|
+
h=HTMLAcceptance.new('/tmp/validation')
|
13
|
+
v=h.validator("<html>foo", 'http://somesite.com/index.html')
|
14
|
+
|
15
|
+
# Note: the second argument (resource) is just an identifier used to name our results files,
|
16
|
+
# and that no data is actually retrieved for you from the URL.
|
17
|
+
|
18
|
+
v.valid?
|
19
|
+
-> false
|
20
|
+
|
21
|
+
v.exceptions
|
22
|
+
-> line 1 column 1 - Warning: missing <!DOCTYPE> declaration
|
23
|
+
-> line 1 column 9 - Warning: plain text isn't allowed in <head> elements
|
24
|
+
-> line 1 column 9 - Warning: inserting missing 'title' element
|
25
|
+
|
26
|
+
v.accept!
|
27
|
+
|
28
|
+
v.valid
|
29
|
+
-> true
|
30
|
+
|
31
|
+
== Accepting Errors
|
32
|
+
|
33
|
+
The HTML Acceptance gem stores data in the passed data_path. After a validation fails,
|
34
|
+
run the html_acceptance rake task (in the gem's lib/tasks) to update validation failures.
|
35
|
+
|
36
|
+
When failures occur, data regarding the failure, the html involved, and the exception
|
37
|
+
return is stored within the data folder passed into HTMLAcceptance. To accept the failures/errors
|
38
|
+
just open the folder, and find the .exception.txt file for the resource and rename it with
|
39
|
+
.accepted.txt. Alternately, to review all failing tests, copy the html_acceptance rake task
|
40
|
+
and run it as follows:
|
41
|
+
|
42
|
+
rake html_acceptance DATA_PATH='/yourproject/validations'
|
43
|
+
|
44
|
+
Replace the data path with whatever folder you passed to HTMLAcceptance when you initially
|
45
|
+
ran the validations.
|
46
|
+
|
47
|
+
|
48
|
+
== NOTES
|
49
|
+
|
50
|
+
This is untested on Windows as I don't have access to a Windows machine at the moment.
|
51
|
+
It is (at least mostly) written so it could work on Windows. Pull requests in this area would
|
52
|
+
be welcomed.
|
53
|
+
|
54
|
+
== Requirements
|
55
|
+
|
56
|
+
HTML Tidy needs to be either installed at /usr/bin/tidy or on the PATH.
|
57
|
+
|
58
|
+
|
59
|
+
== Contributing to html_acceptance
|
60
|
+
|
61
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
62
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
63
|
+
* Fork the project
|
64
|
+
* Start a feature/bugfix branch
|
65
|
+
* Commit and push until you are happy with your contribution
|
66
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
67
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
68
|
+
|
69
|
+
|
70
|
+
Copyright (c) 2011 Eric Beland. See LICENSE.txt for
|
71
|
+
further details.
|
72
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "html_acceptance"
|
16
|
+
gem.homepage = "http://github.com/ericbeland/html_acceptance"
|
17
|
+
gem.license = "MIT"
|
18
|
+
|
19
|
+
gem.summary = %Q{Wrapper for HTMLTidy that lets you accept warnings/errors}
|
20
|
+
gem.description = %Q{HTML Acceptance lets you accept warnings/errors. Less noisey validation will hopefully let you build html validation into your test suite, but break the rules if you must.}
|
21
|
+
gem.email = "ebeland@testomatix.com"
|
22
|
+
gem.authors = ["Eric Beland"]
|
23
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
24
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
25
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
26
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
27
|
+
|
28
|
+
gem.requirements << 'HTML Tidy on the command PATH or at /usr/bin/tidy'
|
29
|
+
end
|
30
|
+
Jeweler::RubygemsDotOrgTasks.new
|
31
|
+
|
32
|
+
require 'rspec/core'
|
33
|
+
require 'rspec/core/rake_task'
|
34
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
35
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
36
|
+
end
|
37
|
+
|
38
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
39
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
40
|
+
spec.rcov = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :spec
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "html_acceptance #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{html_acceptance}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Eric Beland"]
|
12
|
+
s.date = %q{2011-02-16}
|
13
|
+
s.description = %q{HTML Acceptance lets you accept warnings/errors. Less noisey validation will hopefully let you build html validation into your test suite, but break the rules if you must.}
|
14
|
+
s.email = %q{ebeland@testomatix.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"html_acceptance.gemspec",
|
29
|
+
"lib/.rake",
|
30
|
+
"lib/html_acceptance.rb",
|
31
|
+
"lib/html_acceptance/html_acceptance_result.rb",
|
32
|
+
"lib/tasks/html_acceptance.rake",
|
33
|
+
"spec/html_acceptance_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/ericbeland/html_acceptance}
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.requirements = ["HTML Tidy on the command PATH or at /usr/bin/tidy"]
|
40
|
+
s.rubygems_version = %q{1.3.7}
|
41
|
+
s.summary = %q{Wrapper for HTMLTidy that lets you accept warnings/errors}
|
42
|
+
s.test_files = [
|
43
|
+
"spec/html_acceptance_spec.rb",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
55
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
58
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
60
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
66
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
data/lib/.rake
ADDED
File without changes
|
@@ -0,0 +1,85 @@
|
|
1
|
+
|
2
|
+
class HTMLAcceptanceResult
|
3
|
+
attr_accessor :resource, :html, :exceptions
|
4
|
+
|
5
|
+
def initialize(resource, html, datapath, options={})
|
6
|
+
@resource = resource
|
7
|
+
@html = html
|
8
|
+
@exceptions = ''
|
9
|
+
@datapath=datapath
|
10
|
+
@tidyopts = options[:tidy_opts] || "-qi"
|
11
|
+
valid?
|
12
|
+
end
|
13
|
+
|
14
|
+
# takes a .url.txt and loads the data into this object
|
15
|
+
def self.load_from_file(file_root)
|
16
|
+
@resourcepath = File.open("#{file_root}.resource.txt", 'r').read
|
17
|
+
@html = File.open("#{file_root}.html.txt", 'r').read
|
18
|
+
@exceptions = File.open("#{file_root}.exceptions.txt").read
|
19
|
+
end
|
20
|
+
|
21
|
+
# Validates an html string using html tidy. If there are no warnings or exceptions, or
|
22
|
+
# there is a previously accepted exception string that matches exactly, valid? returns true
|
23
|
+
# Line numbers of exceptions are likely to change with any edit, so our validation
|
24
|
+
# compares the exception strings with the lines and columns removed. Name can be a filename,
|
25
|
+
# file system path, or url, so long it is uniquely associated with the passed in html.
|
26
|
+
def valid?
|
27
|
+
@exceptions = validate
|
28
|
+
File.delete(data_path("accepted.txt")) if File.exists?(data_path("accepted.txt")) if @exceptions == ''
|
29
|
+
valid=(@exceptions == '' or accepted?(@exceptions))
|
30
|
+
save_html_and_exceptions
|
31
|
+
valid
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# Saves the exception string for the given url or file path. When next run, if the exception
|
36
|
+
# string is identical, valid? will return true. Note that #exceptions will still list the
|
37
|
+
# exception string, though, even if it is an accepted exception string.
|
38
|
+
def accept!
|
39
|
+
File.open(data_path("accepted.txt"), 'w') {|f| f.write(@exceptions) }
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
# We specifically prefer /usr/bin/tidyby default on *nix as there is another "tidy" programs
|
44
|
+
# that could end up earlier on the path. On snow leopard, tidy was installed at this location
|
45
|
+
# for me by default.
|
46
|
+
def tidy_command
|
47
|
+
is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
|
48
|
+
bin=(is_windows or !File.exists?("/usr/bin/tidy")) ? 'tidy' : '/usr/bin/tidy'
|
49
|
+
"#{bin} #{@tidyopts}"
|
50
|
+
end
|
51
|
+
|
52
|
+
# get the filename for storing a type of data
|
53
|
+
def data_path(filetype)
|
54
|
+
"#{@datapath}.#{filetype}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def save_html_and_exceptions
|
58
|
+
File.open(data_path("exceptions.txt"), 'w') {|f| f.write(@exceptions) }
|
59
|
+
File.open(data_path("html.txt"), 'w') {|f| f.write(@html) }
|
60
|
+
File.open(data_path("resource.txt"), 'w') {|f| f.write(@resource) }
|
61
|
+
end
|
62
|
+
|
63
|
+
# have we previously accepted this exact string for this path?
|
64
|
+
def accepted?(exception_str)
|
65
|
+
exception_str=filter(exception_str)
|
66
|
+
File.exists?(data_path('accepted.txt')) ? filter(File.open(data_path('accepted.txt'),"r").read) == exception_str : false
|
67
|
+
end
|
68
|
+
|
69
|
+
# Line numbers of exceptions are likely to change with any minor edit, so our validation
|
70
|
+
# compares the result strings with the lines and columns removed. This means that
|
71
|
+
# if the errors change position in the file (up or down b/c you add or remove code),
|
72
|
+
# accepted exception strings will remain valid.
|
73
|
+
def filter(str)
|
74
|
+
str.gsub(/line [0-9]+ column [0-9]+ -/, '')
|
75
|
+
# /line [0-9]+ column [0-9]+ - / + =~ "line 1 column 1 - Warning: missing <!DOCTYPE> declaration"
|
76
|
+
end
|
77
|
+
|
78
|
+
def validate
|
79
|
+
stdin, stdout, stderr = Open3.popen3(tidy_command)
|
80
|
+
stdin.puts @html
|
81
|
+
stdin.close
|
82
|
+
result=stderr.read
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# == HTML Acceptance
|
2
|
+
# HTLM Acceptance helps you watch and come to terms with your HTML's validity, or lack thereof.
|
3
|
+
# The idea is to take an html markup string associated with a particular path (file or URL),
|
4
|
+
# and validate it. It is intended to be used in acceptance tests, test suites or a rake task
|
5
|
+
# to alert you to changes in your html's validity so you can fix them, or barring that, review and accept
|
6
|
+
# errors and warnings.
|
7
|
+
|
8
|
+
# ==Paths
|
9
|
+
# When calling the validation routine, a path, or URL is passed.
|
10
|
+
|
11
|
+
# NOTE: HTMLAcceptance never retreives html or reads in files *for* you. It doesn't read files, or call
|
12
|
+
# passed URL's. The purpose of passing a resource path is to give the test a name which saved exceptions
|
13
|
+
# can be stored against and compared to. In theory, the resource could be any distinct string, meaningful or not.
|
14
|
+
|
15
|
+
# If the resource (URL or file) has a saved exception string and it matches, the validation passes.
|
16
|
+
# The user can use a rake task can run this manually and upd ate the accepted exception string.
|
17
|
+
|
18
|
+
require 'rbconfig'
|
19
|
+
require 'html_acceptance/html_acceptance_result'
|
20
|
+
|
21
|
+
class HTMLAcceptance
|
22
|
+
|
23
|
+
|
24
|
+
# The exception_folder is where we store our output. options[:tidyopts], which defaults to "qi"
|
25
|
+
# can be used to override the command line options to html tidy. On *nix, man tidy to see
|
26
|
+
# what else you might use for this string instead of just "-qi"
|
27
|
+
def initialize(data_folder, options={})
|
28
|
+
@data_folder = data_folder
|
29
|
+
@options=options
|
30
|
+
end
|
31
|
+
|
32
|
+
# for each stored exception, yield an html_acceptance object to allow the user to
|
33
|
+
# accept the exception
|
34
|
+
def each_exception
|
35
|
+
Dir.chdir(@data_folder)
|
36
|
+
Dir.glob("*.exceptions.txt").each do |file|
|
37
|
+
if File.open(file, 'r').read != ''
|
38
|
+
yield HTMLAcceptanceResult.load_from_files(file.gsub('.exceptions.txt',''))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def validator(html, resource)
|
44
|
+
datapath=File.join(@data_folder, filenameize(resource))
|
45
|
+
HTMLAcceptanceResult.new(resource, html, datapath, @options)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def filenameize(path)
|
51
|
+
path.gsub!(/www.|^(http:\/\/|\/|C:\\\\)/, '')
|
52
|
+
path.gsub(/[^0-9A-Za-z.]/,'_')
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rake'
|
2
|
+
#require 'html_acceptance'
|
3
|
+
|
4
|
+
desc 'Accept HTML validation exceptions results'
|
5
|
+
task :html_acceptance do
|
6
|
+
|
7
|
+
unless ENV.include?("DATA_PATH")
|
8
|
+
raise "usage: rake html_acceptance DATA_PATH=foo"
|
9
|
+
end
|
10
|
+
|
11
|
+
HTMLAcceptance.new(env['DATA_PATH']).each_exception do |result|
|
12
|
+
$stdout.puts "Validation Exceptions:\n #{result}"
|
13
|
+
$stdout.puts "Accept (y)es or (n)o"
|
14
|
+
sin=$stdin.gets
|
15
|
+
result.accept! if sin.first == 'y'
|
16
|
+
exit if sin == 'exit'
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "HtmlAcceptance" do
|
4
|
+
|
5
|
+
def tmp_path
|
6
|
+
is_windows=(RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
|
7
|
+
is_windows ? 'c:\temp\validation' : '/tmp/validation'
|
8
|
+
end
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
FileUtils.mkdir '/tmp/validation' if !File.exists?('/tmp/validation')
|
12
|
+
@h=HTMLAcceptance.new('/tmp/validation')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return false for invalid xml" do
|
16
|
+
result=@h.validator(bad_html, "http://myothersite.com").valid?.should be_false
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return true for valid html" do
|
20
|
+
result=@h.validator(good_html, "http://mysite.com").valid?.should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have an exception string for invalid xml" do
|
24
|
+
result=@h.validator(bad_html, "http://myfavoritesite.com")
|
25
|
+
(result.exceptions.empty?).should be_false
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return true for valid? if exceptions are accepted" do
|
29
|
+
result=@h.validator(bad_html, "http://mynewsite.com")
|
30
|
+
result.accept!
|
31
|
+
result=@h.validator(bad_html, "http://mynewsite.com").valid?.should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should show no exceptions for a truly valid file" do
|
35
|
+
result=@h.validator(good_html, "http://mybestsite.com")
|
36
|
+
(result.exceptions == '').should be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should still show exceptions when returning valid for an accepted exception string" do
|
40
|
+
result=@h.validator(bad_html, "http://myworstsite.com")
|
41
|
+
result.accept!
|
42
|
+
result=@h.validator(bad_html, "http://myworstsite.com")
|
43
|
+
result.valid?.should be_true
|
44
|
+
(result.exceptions.length == 0).should be_false
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should reset exceptions after each call to valid?" do
|
48
|
+
result=@h.validator(bad_html, "http://myuglysite.com")
|
49
|
+
result=@h.validator(good_html, "http://myuglysite.com")
|
50
|
+
(result.exceptions.length == 0).should be_true
|
51
|
+
result.valid?.should be_true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should reset accepted exceptions string after seeing valid html for a path" do
|
55
|
+
result=@h.validator(bad_html, "http://notmysite.com")
|
56
|
+
result.accept!
|
57
|
+
result=@h.validator(bad_html, "http://notmysite.com").valid?.should be_true
|
58
|
+
# now we see valid, so we should reset
|
59
|
+
result=@h.validator(good_html, "http://notmysite.com").valid?.should be_true
|
60
|
+
result=@h.validator(bad_html, "http://notmysite.com").valid?.should be_false
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not pass different exception" do
|
64
|
+
result=@h.validator(bad_html, "http://mycoolsite.com")
|
65
|
+
result.accept!
|
66
|
+
e1=result.exceptions
|
67
|
+
result=@h.validator("<html></body></html>", "http://mycoolsite.com").valid?.should be_false
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should let me pass a tidy option" do
|
71
|
+
@h=HTMLAcceptance.new('/tmp/validation', :tidy_opts=>"-e")
|
72
|
+
result=@h.validator("<html>foo", 'c:\mycoolapp\somesite.html')
|
73
|
+
result.exceptions.include?("were found!").should be_true
|
74
|
+
@h=HTMLAcceptance.new('/tmp/validation')
|
75
|
+
result=@h.validator("<html>foo", 'c:\mycoolapp\somesite.html')
|
76
|
+
result.exceptions.include?("were found!").should be_false
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def bad_html
|
82
|
+
'<html><title>the title<title></head><body><p>blah blah</body></html>'
|
83
|
+
end
|
84
|
+
|
85
|
+
def good_html
|
86
|
+
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><title>the title</title></head><body><p>a paragraph</body></html>'
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'html_acceptance'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: html_acceptance
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Eric Beland
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-16 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
name: rspec
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 2
|
33
|
+
- 3
|
34
|
+
- 0
|
35
|
+
version: 2.3.0
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
name: bundler
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 23
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 0
|
50
|
+
- 0
|
51
|
+
version: 1.0.0
|
52
|
+
requirement: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
name: jeweler
|
57
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 7
|
63
|
+
segments:
|
64
|
+
- 1
|
65
|
+
- 5
|
66
|
+
- 2
|
67
|
+
version: 1.5.2
|
68
|
+
requirement: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
name: rcov
|
73
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirement: *id004
|
83
|
+
description: HTML Acceptance lets you accept warnings/errors. Less noisey validation will hopefully let you build html validation into your test suite, but break the rules if you must.
|
84
|
+
email: ebeland@testomatix.com
|
85
|
+
executables: []
|
86
|
+
|
87
|
+
extensions: []
|
88
|
+
|
89
|
+
extra_rdoc_files:
|
90
|
+
- LICENSE.txt
|
91
|
+
- README.rdoc
|
92
|
+
files:
|
93
|
+
- .document
|
94
|
+
- .rspec
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.rdoc
|
99
|
+
- Rakefile
|
100
|
+
- VERSION
|
101
|
+
- html_acceptance.gemspec
|
102
|
+
- lib/.rake
|
103
|
+
- lib/html_acceptance.rb
|
104
|
+
- lib/html_acceptance/html_acceptance_result.rb
|
105
|
+
- lib/tasks/html_acceptance.rake
|
106
|
+
- spec/html_acceptance_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
has_rdoc: true
|
109
|
+
homepage: http://github.com/ericbeland/html_acceptance
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: 3
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 3
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
version: "0"
|
135
|
+
requirements:
|
136
|
+
- HTML Tidy on the command PATH or at /usr/bin/tidy
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 1.3.7
|
139
|
+
signing_key:
|
140
|
+
specification_version: 3
|
141
|
+
summary: Wrapper for HTMLTidy that lets you accept warnings/errors
|
142
|
+
test_files:
|
143
|
+
- spec/html_acceptance_spec.rb
|
144
|
+
- spec/spec_helper.rb
|