htmldoc-hulihanapplications 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,101 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class BasicTest < Test::Unit::TestCase
4
+
5
+ def test_options
6
+ all_options = PDF::HTMLDoc.class_eval do
7
+ class_variable_get(:@@all_options)
8
+ end
9
+ all_options.each do |option|
10
+ pdf = PDF::HTMLDoc.new
11
+ pdf.set_option option, :default
12
+ assert_equal :default, pdf.instance_variable_get(:@options)[option]
13
+ assert_equal 1, pdf.instance_variable_get(:@options).size
14
+ pdf.set_option option, nil
15
+ assert_equal 0, pdf.instance_variable_get(:@options).size
16
+ end
17
+ pdf = PDF::HTMLDoc.new
18
+ i = 0
19
+ all_options.each do |option|
20
+ pdf.set_option option, i
21
+ assert_equal i, pdf.instance_variable_get(:@options)[option]
22
+ assert_equal i + 1, pdf.instance_variable_get(:@options).size
23
+ i += 1
24
+ end
25
+ assert_raise(PDF::HTMLDocException) { pdf.set_option :test, :value }
26
+ assert_raise(PDF::HTMLDocException) { pdf.set_option "test", "value" }
27
+ end
28
+
29
+ def test_header
30
+ pdf = PDF::HTMLDoc.new
31
+ pdf.header ".t."
32
+ assert_equal ".t.", pdf.instance_variable_get(:@options)[:header]
33
+ assert_equal 1, pdf.instance_variable_get(:@options).size
34
+ end
35
+
36
+ def test_footer
37
+ pdf = PDF::HTMLDoc.new
38
+ pdf.footer ".t."
39
+ assert_equal ".t.", pdf.instance_variable_get(:@options)[:footer]
40
+ assert_equal 1, pdf.instance_variable_get(:@options).size
41
+ end
42
+
43
+ def test_get_final_value
44
+ # Those tests are not exhaustive, but will ensure a reasonable
45
+ # level of functionality
46
+ pdf = PDF::HTMLDoc.new
47
+ tests = [["--webpage", :webpage, true],
48
+ ["--no-encryption", :encryption, :none],
49
+ ["--no-encryption", :encryption, :no],
50
+ ["--no-encryption", :encryption, false],
51
+ ["--encryption", :encryption, true],
52
+ ["--no-encryption", :encryption, :none],
53
+ ["--no-jpeg", :jpeg, :no],
54
+ ["--jpeg 80", :jpeg, 80],
55
+ ["--bodycolor black", :bodycolor, :black],
56
+ ["--left 12in", :left, "12in"],
57
+ ["--cookies 'name=value;other=test'", :cookies, { :name => "value", :other => "test" }]]
58
+ tests.each do |test|
59
+ assert_equal test.first, pdf.send(:get_final_value, *test[1,2])
60
+ end
61
+ end
62
+
63
+ def test_get_command_options
64
+ # Those tests are not exhaustive, but should ensure a reasonable
65
+ # level of functionality.
66
+ pdf = PDF::HTMLDoc.new
67
+ tests = [["--webpage", :webpage, true],
68
+ ["--no-encryption", :encryption, :none],
69
+ ["--jpeg 80", :jpeg, 80],
70
+ ["--bodycolor black", :bodycolor, :black],
71
+ ["--left 12in", :left, "12in"],
72
+ ["--cookies 'name=value;other=test'", :cookies, { :name => "value", :other => "test" }]]
73
+ tests.each do |test|
74
+ pdf.send(:set_option, *test[1,2])
75
+ end
76
+ command_options = tests.collect { |test| test.first }
77
+ command_options = (command_options + ["--format " + PDF::PDF]).sort.join(" ")
78
+ assert_equal command_options, pdf.send(:get_command_options)
79
+ end
80
+
81
+ def test_get_command_pages
82
+ # Those tests are not exhaustive, but should ensure a reasonable
83
+ # level of functionality.
84
+ pdf = PDF::HTMLDoc.new
85
+ tempfile = Tempfile.new("htmldoc.test")
86
+ pages = ["http://example.org/", tempfile.path]
87
+ tmpstring = "1234567890"
88
+ tmpstring += "1234567890" while File.exists?(tmpstring)
89
+ pages << tmpstring
90
+ pages.each do |page|
91
+ pdf << page
92
+ end
93
+ command_pages = pdf.send(:get_command_pages)
94
+ pages[2] = pdf.instance_variable_get(:@tempfiles)[0].path
95
+ assert_equal pages.join(" "), command_pages
96
+ ensure
97
+ tempfiles = pdf.instance_variable_get(:@tempfiles)
98
+ tempfiles.each { |t| t.close }
99
+ end
100
+
101
+ end
@@ -0,0 +1,135 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class GenerationTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ # If you are using a different program path, you should configure
7
+ # it here.
8
+ @program_path = PDF::HTMLDoc.program_path
9
+ end
10
+
11
+ def test_program_path
12
+ data = IO.popen(@program_path + " --version 2>&1") { |s| s.read }
13
+ assert_equal 0, $?.exitstatus
14
+ assert_match(/^1.((8.2\d)|9-current)/, data)
15
+ end
16
+
17
+ def test_generation
18
+ # Those tests are not exhaustive, but will ensure a reasonable
19
+ # level of functionality. Output to directories is not tested for
20
+ # now.
21
+ basic_test(PDF::HTML)
22
+ basic_test(PDF::HTML, "http://foo.com/\nhttp://bar.com/")
23
+ basic_test(PDF::PS)
24
+ basic_test(PDF::PDF)
25
+ end
26
+
27
+ def test_generation_results
28
+ pdf = PDF::HTMLDoc.new
29
+ pdf.set_option :webpage, true
30
+ pdf.set_option :toc, false
31
+ pdf << "<h1>Random title</h1>"
32
+ assert_kind_of String, pdf.generate
33
+ assert_not_nil pdf.result[:bytes]
34
+ assert_not_nil pdf.result[:pages]
35
+ assert_equal 0, pdf.errors.size
36
+ assert_equal 1, pdf.result[:pages]
37
+ end
38
+
39
+ def test_invalid_program_path
40
+ PDF::HTMLDoc.program_path = @program_path + "-non-existing-path"
41
+ assert_raise(PDF::HTMLDocException) { PDF::HTMLDoc.new.generate }
42
+ ensure
43
+ PDF::HTMLDoc.program_path = @program_path
44
+ end
45
+
46
+ def test_generation_errors
47
+ # This test can fail if the collapsing wavefront of the Internet
48
+ # somehow becomes random.
49
+ # Test invalid input
50
+ pdf = PDF::HTMLDoc.new
51
+ pdf.set_option :outfile, "test.pdf"
52
+ pdf << "http://#{simple_uid(".com")}:12345/#{simple_uid(".html")}"
53
+ pdf.generate
54
+ assert_not_equal 0, pdf.errors.size
55
+ assert_nil pdf.result[:bytes]
56
+ assert_nil pdf.result[:pages]
57
+ # Test an invalid option
58
+ pdf = PDF::HTMLDoc.new
59
+ pdf.set_option :outfile, "test.pdf"
60
+ pdf << "http://#{simple_uid(".com")}:12345/#{simple_uid(".html")} --non-existing-option"
61
+ pdf.generate
62
+ assert_not_equal 0, pdf.errors.size
63
+ assert_nil pdf.result[:bytes]
64
+ assert_nil pdf.result[:pages]
65
+ end
66
+
67
+ private
68
+
69
+ def basic_test(format, page = %Q(<h1>Page 1</h1><p>Test.</p><h1>Page 2</h1><p>Test.</p>\nhttp://foo.com/))
70
+ # Temporary files
71
+ path1, path2 = (1..2).collect { |i| Dir.tmpdir + "/#{i}.#{format}" }
72
+ # Create a temporary file for the duration of the test
73
+ Tempfile.open("htmldoc.test") do |tempfile|
74
+ # Load the temporary file with some test datas
75
+ tempfile.binmode
76
+ tempfile.write(page)
77
+ tempfile.flush
78
+ # Simple format test
79
+ pdf = PDF::HTMLDoc.new(format)
80
+ pdf.set_option :outfile, path1
81
+ pdf.add_page tempfile.path
82
+ assert_equal true, pdf.generate
83
+ assert_equal pdf.result[:output], execute_htmldoc(path2, tempfile.path, "--format #{format}")
84
+ # Delete temporary files
85
+ File.delete(path1) if File.exists?(path1)
86
+ File.delete(path2) if File.exists?(path2)
87
+ # Simple webpag format test
88
+ pdf = PDF::HTMLDoc.new(format)
89
+ pdf.set_option :outfile, path1
90
+ pdf.set_option :webpage, true
91
+ pdf.add_page tempfile.path
92
+ assert_equal true, pdf.generate
93
+ assert_equal pdf.result[:output], execute_htmldoc(path2, tempfile.path, "--webpage --format #{format}")
94
+ # Delete temporary files
95
+ File.delete(path1) if File.exists?(path1)
96
+ File.delete(path2) if File.exists?(path2)
97
+ # Simple options test
98
+ pdf = PDF::HTMLDoc.new(format)
99
+ pdf.set_option :outfile, path1
100
+ pdf.set_option :bodycolor, :black
101
+ pdf.add_page tempfile.path
102
+ assert_equal true, pdf.generate
103
+ assert_equal pdf.result[:output], execute_htmldoc(path2, tempfile.path, "--bodycolor black --format #{format}")
104
+ # Delete temporary files
105
+ File.delete(path1) if File.exists?(path1)
106
+ File.delete(path2) if File.exists?(path2)
107
+ # Free text generate test
108
+ pdf = PDF::HTMLDoc.new(format)
109
+ pdf.add_page page
110
+ pdf.generate
111
+ assert_equal pdf.result[:output], execute_htmldoc(path2, tempfile.path, "--format #{format}")
112
+ # Delete temporary files
113
+ File.delete(path2) if File.exists?(path2)
114
+ # Inline generation test
115
+ result = PDF::HTMLDoc.create(format) do |p|
116
+ p.set_option :outfile, path1
117
+ p.set_option :bodycolor, :black
118
+ p.add_page tempfile.path
119
+ end
120
+ assert_equal true, result
121
+ end
122
+ end
123
+
124
+ def execute_htmldoc(output, input, options)
125
+ IO.popen("#{@program_path} #{options} -f #{output} #{input} 2>&1") { |s| s.read }
126
+ end
127
+
128
+ def simple_uid(extension)
129
+ chars = ('A'..'Z').to_a + ('0'..'9').to_a
130
+ (1..100).inject("") { |r, i| r + chars[rand(chars.length)] }
131
+ end
132
+
133
+ end
134
+
135
+ # LocalWords: HTMLDOC
@@ -0,0 +1,2 @@
1
+ require "test/unit"
2
+ require File.dirname(__FILE__) + "/../lib/htmldoc"
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: htmldoc-hulihanapplications
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 4
10
+ version: 0.2.4
11
+ platform: ruby
12
+ authors:
13
+ - Hulihan Applications
14
+ - Dave Hulihan
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-09-09 00:00:00 -06:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ type: :development
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ name: shoulda
34
+ version_requirements: *id001
35
+ prerelease: false
36
+ - !ruby/object:Gem::Dependency
37
+ type: :development
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 23
44
+ segments:
45
+ - 1
46
+ - 0
47
+ - 0
48
+ version: 1.0.0
49
+ name: bundler
50
+ version_requirements: *id002
51
+ prerelease: false
52
+ - !ruby/object:Gem::Dependency
53
+ type: :development
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 7
60
+ segments:
61
+ - 1
62
+ - 6
63
+ - 4
64
+ version: 1.6.4
65
+ name: jeweler
66
+ version_requirements: *id003
67
+ prerelease: false
68
+ - !ruby/object:Gem::Dependency
69
+ type: :development
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ name: rcov
80
+ version_requirements: *id004
81
+ prerelease: false
82
+ description: "A fork of the craigw's htmldoc: https://github.com/craigw/htmldoc."
83
+ email: dave@hulihanapplications.com
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files:
89
+ - LICENSE.txt
90
+ - README.txt
91
+ files:
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - History.txt
95
+ - LICENSE.txt
96
+ - Manifest.txt
97
+ - README.txt
98
+ - Rakefile
99
+ - VERSION
100
+ - htmldoc-hulihanapplications.gemspec
101
+ - init.rb
102
+ - lib/htmldoc.rb
103
+ - lib/htmldoc/version.rb
104
+ - setup.rb
105
+ - test/basic_test.rb
106
+ - test/generation_test.rb
107
+ - test/test_helper.rb
108
+ has_rdoc: true
109
+ homepage: http://github.com/hulihanapplications/htmldoc
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
+
137
+ rubyforge_project:
138
+ rubygems_version: 1.6.2
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: Wrapper around HTMLDOC (canonical repository)
142
+ test_files: []
143
+