lablr 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 CHANGED
@@ -1,121 +1,91 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: lablr
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 2
10
- version: 0.1.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Hulihan Applications
14
9
  - Dave Hulihan
15
10
  autorequire:
16
11
  bindir: bin
17
12
  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: :runtime
24
- requirement: &id001 !ruby/object:Gem::Requirement
13
+ date: 2012-01-16 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: htmldoc-hulihanapplications
17
+ requirement: &16898740 !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
33
- name: htmldoc
34
- version_requirements: *id001
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
35
24
  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: 3
44
- segments:
45
- - 0
46
- version: "0"
25
+ version_requirements: *16898740
26
+ - !ruby/object:Gem::Dependency
47
27
  name: shoulda
48
- version_requirements: *id002
49
- prerelease: false
50
- - !ruby/object:Gem::Dependency
28
+ requirement: &16898140 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
51
34
  type: :development
52
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ prerelease: false
36
+ version_requirements: *16898140
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ requirement: &16897540 !ruby/object:Gem::Requirement
53
40
  none: false
54
- requirements:
41
+ requirements:
55
42
  - - ~>
56
- - !ruby/object:Gem::Version
57
- hash: 23
58
- segments:
59
- - 1
60
- - 0
61
- - 0
43
+ - !ruby/object:Gem::Version
62
44
  version: 1.0.0
63
- name: bundler
64
- version_requirements: *id003
65
- prerelease: false
66
- - !ruby/object:Gem::Dependency
67
45
  type: :development
68
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ prerelease: false
47
+ version_requirements: *16897540
48
+ - !ruby/object:Gem::Dependency
49
+ name: jeweler
50
+ requirement: &16896980 !ruby/object:Gem::Requirement
69
51
  none: false
70
- requirements:
52
+ requirements:
71
53
  - - ~>
72
- - !ruby/object:Gem::Version
73
- hash: 7
74
- segments:
75
- - 1
76
- - 6
77
- - 4
54
+ - !ruby/object:Gem::Version
78
55
  version: 1.6.4
79
- name: jeweler
80
- version_requirements: *id004
81
- prerelease: false
82
- - !ruby/object:Gem::Dependency
83
56
  type: :development
84
- requirement: &id005 !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- hash: 3
90
- segments:
91
- - 0
92
- version: "0"
93
- name: rcov
94
- version_requirements: *id005
95
57
  prerelease: false
96
- - !ruby/object:Gem::Dependency
97
- type: :development
98
- requirement: &id006 !ruby/object:Gem::Requirement
58
+ version_requirements: *16896980
59
+ - !ruby/object:Gem::Dependency
60
+ name: rcov
61
+ requirement: &16896500 !ruby/object:Gem::Requirement
99
62
  none: false
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- hash: 3
104
- segments:
105
- - 0
106
- version: "0"
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *16896500
70
+ - !ruby/object:Gem::Dependency
107
71
  name: rspec
108
- version_requirements: *id006
72
+ requirement: &16896020 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
109
79
  prerelease: false
110
- description: A Ruby Gem for generating printable labels in a variety of formats(pdf, html, etc.) and templates(Avery, etc.).
80
+ version_requirements: *16896020
81
+ description: A Ruby Gem for generating printable labels in a variety of formats(pdf,
82
+ html, etc.) and templates(Avery, etc.).
111
83
  email: dave@hulihanapplications.com
112
84
  executables: []
113
-
114
85
  extensions: []
115
-
116
- extra_rdoc_files:
86
+ extra_rdoc_files:
117
87
  - README.textile
118
- files:
88
+ files:
119
89
  - .document
120
90
  - Gemfile
121
91
  - Gemfile.lock
@@ -133,39 +103,45 @@ files:
133
103
  - spec/lib/lablr_spec.rb
134
104
  - spec/spec_helper.rb
135
105
  - test.rb
136
- has_rdoc: true
106
+ - vendor/gems/htmldoc/History.txt
107
+ - vendor/gems/htmldoc/LICENSE.txt
108
+ - vendor/gems/htmldoc/Manifest.txt
109
+ - vendor/gems/htmldoc/README.txt
110
+ - vendor/gems/htmldoc/Rakefile
111
+ - vendor/gems/htmldoc/VERSION
112
+ - vendor/gems/htmldoc/init.rb
113
+ - vendor/gems/htmldoc/lib/htmldoc.rb
114
+ - vendor/gems/htmldoc/lib/htmldoc/version.rb
115
+ - vendor/gems/htmldoc/setup.rb
116
+ - vendor/gems/htmldoc/test/basic_test.rb
117
+ - vendor/gems/htmldoc/test/generation_test.rb
118
+ - vendor/gems/htmldoc/test/test_helper.rb
137
119
  homepage: http://github.com/hulihanapplications/lablr
138
- licenses:
120
+ licenses:
139
121
  - MIT
140
122
  post_install_message:
141
123
  rdoc_options: []
142
-
143
- require_paths:
124
+ require_paths:
144
125
  - lib
145
- required_ruby_version: !ruby/object:Gem::Requirement
126
+ required_ruby_version: !ruby/object:Gem::Requirement
146
127
  none: false
147
- requirements:
148
- - - ">="
149
- - !ruby/object:Gem::Version
150
- hash: 3
151
- segments:
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ segments:
152
133
  - 0
153
- version: "0"
154
- required_rubygems_version: !ruby/object:Gem::Requirement
134
+ hash: 2161456232915710564
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
136
  none: false
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- hash: 3
160
- segments:
161
- - 0
162
- version: "0"
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
163
141
  requirements: []
164
-
165
142
  rubyforge_project:
166
- rubygems_version: 1.6.2
143
+ rubygems_version: 1.8.15
167
144
  signing_key:
168
145
  specification_version: 3
169
146
  summary: Generate printable labels with Ruby!
170
147
  test_files: []
171
-