html_acceptance 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.7
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{html_acceptance}
8
- s.version = "0.1.5"
8
+ s.version = "0.1.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Eric Beland"]
@@ -5,8 +5,9 @@
5
5
  # to alert you to changes in your html's validity so you can fix them, or barring that, review and accept
6
6
  # errors and warnings.
7
7
 
8
- # ==Paths
9
- # When calling the validation routine, a path, or URL is passed.
8
+ # ==Resource paths
9
+ # When calling the validation routine, a path, or URL is passed. This is used internally to name
10
+ # the resulting validation output files.
10
11
 
11
12
  # NOTE: HTMLAcceptance never retreives html or reads in files *for* you. It doesn't read files, or call
12
13
  # passed URL's. The purpose of passing a resource path is to give the test a name which saved exceptions
@@ -21,16 +22,20 @@ require 'html_acceptance/html_acceptance_result'
21
22
  class HTMLAcceptance
22
23
 
23
24
 
24
- # The exception_folder is where we store our output. options[:tidyopts], which defaults to "qi"
25
+ # The data_folder is where we store our output. options[:tidyopts], which defaults to "-qi"
25
26
  # 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
+ # what else you might use for this string instead of "-qi", however "-qi" is probably what
28
+ # you want 95% of the time.
29
+
30
+ # It may be useful to pass a subfolder in your project as the data_folder, so your
31
+ # html acceptance status and validation results are stored along with your source.
27
32
  def initialize(data_folder, options={})
28
33
  @data_folder = data_folder
29
34
  @options=options
30
35
  end
31
36
 
32
- # for each stored exception, yield an html_acceptance object to allow the user to
33
- # accept the exception
37
+ # For each stored exception, yield an HTMLAcceptanceResult object to allow the user to
38
+ # call .accept! on the exception if it is OK.
34
39
  def each_exception
35
40
  Dir.chdir(@data_folder)
36
41
  Dir.glob("*.exceptions.txt").each do |file|
@@ -47,8 +52,9 @@ class HTMLAcceptance
47
52
 
48
53
  private
49
54
 
55
+ # take a url or filepath, trim and sanitize it for use as a filename
50
56
  def filenameize(path)
51
- path.gsub!(/www.|^(http:\/\/|\/|C:\\\\)/, '')
57
+ path.gsub!(/www.|^(http:\/\/|\/|C:\\)/, '')
52
58
  path.gsub(/[^0-9A-Za-z.]/,'_')
53
59
  end
54
60
 
@@ -2,13 +2,9 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "HtmlAcceptance" do
4
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
5
  before(:each) do
11
- FileUtils.mkdir '/tmp/validation' if !File.exists?('/tmp/validation')
6
+ FileUtils.mkdir tmp_path if !File.exists?('/tmp/validation')
7
+ clean_dir(tmp_path)
12
8
  @h=HTMLAcceptance.new('/tmp/validation')
13
9
  end
14
10
 
@@ -60,7 +56,7 @@ describe "HtmlAcceptance" do
60
56
  result=@h.validator(bad_html, "http://notmysite.com").valid?.should be_false
61
57
  end
62
58
 
63
- it "should not pass different exception" do
59
+ it "should not pass a different non-accepted exception" do
64
60
  result=@h.validator(bad_html, "http://mycoolsite.com")
65
61
  result.accept!
66
62
  e1=result.exceptions
@@ -76,6 +72,20 @@ describe "HtmlAcceptance" do
76
72
  result.exceptions.include?("were found!").should be_false
77
73
  end
78
74
 
75
+
76
+ it "should yeild exception results" do
77
+ @h=HTMLAcceptance.new('/tmp/validation', :tidy_opts=>"-e")
78
+ result=@h.validator("<html>foo", 'c:\evencooler.com\somesite.html')
79
+ had_exceptions=false
80
+ @h.each_exception do |e|
81
+ had_exceptions=true
82
+ e.is_a?(HTMLAcceptanceResult).should be_true
83
+ (e.resource.length > 0).should be_true
84
+ (e.html.length > 0).should be_true
85
+ end
86
+ had_exceptions.should be_true
87
+ end
88
+
79
89
  private
80
90
 
81
91
  def bad_html
@@ -86,4 +96,15 @@ describe "HtmlAcceptance" do
86
96
  '<!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
97
  end
88
98
 
99
+ def tmp_path
100
+ is_windows=(RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
101
+ is_windows ? 'c:\temp\validation' : '/tmp/validation'
102
+ end
103
+
104
+ # clean our temp dir without killing it
105
+ def clean_dir(dir)
106
+ Dir.chdir(dir)
107
+ Dir.glob('*').each {|f| FileUtils.rm(f) }
108
+ end
109
+
89
110
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_acceptance
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 7
10
+ version: 0.1.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eric Beland