spec/pdfkit_spec.rb in pdfkit-0.8.4.1 vs spec/pdfkit_spec.rb in pdfkit-0.8.4.2
- old
+ new
@@ -21,10 +21,17 @@
pdfkit = PDFKit.new(File.new(file_path))
expect(pdfkit.source).to be_file
expect(pdfkit.source.to_s).to eq(file_path)
end
+ it "accepts a Tempfile as the source" do
+ file_path = File.join(SPEC_ROOT,'fixtures','example.html')
+ pdfkit = PDFKit.new(Tempfile.new(file_path))
+ expect(pdfkit.source).to be_file
+ expect(pdfkit.source.to_s).to match /^#{Dir.tmpdir}/
+ end
+
# Options
## options keys
it "drops options without values" do
pdfkit = PDFKit.new('html', :page_size => nil)
expect(pdfkit.options).not_to have_key('--page-size')
@@ -250,10 +257,16 @@
file_path = File.join(SPEC_ROOT,'fixtures','example.html')
pdfkit = PDFKit.new(File.new(file_path))
expect(pdfkit.command).to match /#{file_path} -$/
end
+ it "specifies the path to the source if it is a tempfile" do
+ file_path = File.join(SPEC_ROOT,'fixtures','example.html')
+ pdfkit = PDFKit.new(Tempfile.new(file_path))
+ expect(pdfkit.command).to match /#{Dir.tmpdir}\S+ -$/
+ end
+
it "specifies the path for the ouput if a path is given" do
file_path = "/path/to/output.pdf"
pdfkit = PDFKit.new("html")
expect(pdfkit.command(file_path)).to match /#{file_path}$/
end
@@ -497,10 +510,10 @@
end
#NOTICE: This test is failed if use wkhtmltopdf-binary (0.9.9.1)
it "throws an error if it is unable to connect" do
pdfkit = PDFKit.new("http://google.com/this-should-not-be-found/404.html")
- expect { pdfkit.to_pdf }.to raise_error /exitstatus=1/
+ expect { pdfkit.to_pdf }.to raise_error PDFKit::ImproperWkhtmltopdfExitStatus, /exitstatus=1/
end
it "does not throw an error if it is unable to connect", pending: 'this test works for wkhtmltopdf-binary (0.9.9.1)' do
pdfkit = PDFKit.new("http://localhost/this-should-not-be-found/404.html")
pdf = pdfkit.to_pdf