Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

changed spec tests to Test Unit Assertions and added more tests

  • Loading branch information...
commit 3eaac99656278c5053caa2d38f30cc6822f83b33 1 parent 7ebc2f3
Lleïr Borràs Metje authored
View
26 Rakefile
@@ -1,9 +1,23 @@
-require 'rubygems'
-require 'spec/rake/spectask'
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
-Spec::Rake::SpecTask.new do |t|
- t.warning = true
- t.rcov = true
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the wicked_pdf plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
end
-task :default => :spec
+desc 'Generate documentation for the wicked_pdf plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'WickedPdf'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
View
12 lib/pdf_helper.rb
@@ -35,12 +35,6 @@ def make_and_send_pdf(pdf_name, options = {})
end
end
- def parse_options opts
- s = "#{parse_header_footer(:header => opts.delete(:header), :footer => opts.delete(:footer), :layout => opts[:layout])} "
- s += "#{parse_toc(opts.delete(:toc))} #{parse_outline(opts.delete(:outline))} "
- s + "#{parse_margins(opts.delete(:margin))} #{parse_others(opts)} "
- end
-
def make_option name, value, type=:string
"--#{name.gsub('_', '-')} " + case type
when :boolean: ""
@@ -53,6 +47,12 @@ def make_options opts, names, prefix="", type=:string
names.collect {|o| make_option("#{prefix.blank? ? "" : prefix + "-"}#{o.to_s}", opts[o], type) unless opts[o].blank?}.join
end
+ def parse_options opts
+ "#{parse_header_footer(:header => opts.delete(:header), :footer => opts.delete(:footer), :layout => opts[:layout])} " + \
+ "#{parse_toc(opts.delete(:toc))} #{parse_outline(opts.delete(:outline))} " + \
+ "#{parse_margins(opts.delete(:margin))} #{parse_others(opts)} "
+ end
+
def parse_header_footer opts
r=""
[:header, :footer].collect do |hf|
View
6 lib/wicked_pdf.rb
@@ -9,9 +9,11 @@ class WickedPdf
def initialize(wkhtmltopdf_binary_path = nil)
@exe_path = wkhtmltopdf_binary_path
- @exe_path ||= WICKED_PDF[:exe_path] unless WICKED_PDF.blank?
+ @exe_path ||= WICKED_PDF[:exe_path] unless WICKED_PDF.empty?
@exe_path ||= `which wkhtmltopdf`.chomp
- raise "Location of wkhtmltopdf unknown" if @exe_path.blank?
+ raise "Location of wkhtmltopdf unknown" if @exe_path.empty?
+ raise "Bad wkhtmltopdf's path" unless File.exists?(@exe_path)
+ raise "Wkhtmltopdf is not executable" unless File.executable?(@exe_path)
end
def pdf_from_string(string, options=nil)
View
25 spec/wicked_pdf_spec.rb
@@ -1,25 +0,0 @@
-require File.dirname(__FILE__) + "/../lib/wicked_pdf.rb"
-
-HTML_DOCUMENT = "<html><body>Hello World</body></html>"
-
-describe "WickedPdf" do
-
- it "should generate PDF from html document" do
- wp = WickedPdf.new
- pdf = wp.pdf_from_string HTML_DOCUMENT
- pdf.start_with?("%PDF-1.4").should be_true
- pdf.rstrip.end_with?("%%EOF").should be_true
- pdf.length.should > 100
- end
-
- it "should raise exception when no path to wkhtmltopdf" do
- lambda { WickedPdf.new "" }.should raise_error
- end
-
- it "should raise exception when pdf generation fails" do
- wp = WickedPdf.new("/i/do/not/exist/notwkhtmltopdf")
- lambda { wp.pdf_from_string HTML_DOCUMENT }.should raise_error
- end
-
-end
-
Please sign in to comment.
Something went wrong with that request. Please try again.