require "spec_helper" describe BrDanfe::Document do let(:base_dir) { "./spec/fixtures/lib/"} let(:output_pdf) { "#{base_dir}output.pdf" } let(:xml) { BrDanfe::XML.new(xml_as_string) } describe "#lie" do before do subject.render File.delete(output_pdf) if File.exist?(output_pdf) end context "when IE is valid" do let(:xml_as_string) do <<-eos 964508990089 SP eos end it "renders a box with a formated IE to the pdf" do expect(File.exist?(output_pdf)).to be_falsey subject.lie 0.80, 3.94, 1, 1, xml, "transporta/UF", "transporta/IE" subject.render_file output_pdf expect("#{base_dir}document#lie-valid.pdf").to be_same_file_as(output_pdf) end end context "when IE is invalid" do let(:xml_as_string) do <<-eos 123 SC eos end it "renders a blank box to the pdf" do expect(File.exist?(output_pdf)).to be_falsey subject.lie 0.80, 3.94, 1, 1, xml, "transporta/UF", "transporta/IE" subject.render_file output_pdf expect("#{base_dir}document#lie-invalid.pdf").to be_same_file_as(output_pdf) end end context "when IE is blank" do let(:xml_as_string) do <<-eos eos end it "renders a blank box to the pdf" do expect(File.exist?(output_pdf)).to be_falsey subject.lie 0.80, 3.94, 1, 1, xml, "transporta/UF", "transporta/IE" subject.render_file output_pdf expect("#{base_dir}document#lie-blank.pdf").to be_same_file_as(output_pdf) end end end describe "#lcnpj" do before do subject.render File.delete(output_pdf) if File.exist?(output_pdf) end context "when CNPJ is valid" do let(:xml_as_string) do <<-eos 71434064000149 eos end it "renders a box with a formated CNPJ to the pdf" do expect(File.exist?(output_pdf)).to be_falsey subject.lcnpj 0.80, 3.94, 1, 1, xml, "transporta/CNPJ" subject.render_file output_pdf expect("#{base_dir}document#lcnpj-valid.pdf").to be_same_file_as(output_pdf) end end context "when CNPJ is invalid" do let(:xml_as_string) do <<-eos 714 eos end it "renders a blank box to the pdf" do expect(File.exist?(output_pdf)).to be_falsey subject.lcnpj 0.80, 3.94, 1, 1, xml, "transporta/CNPJ" subject.render_file output_pdf expect("#{base_dir}document#lcnpj-invalid.pdf").to be_same_file_as(output_pdf) end end context "when CNPJ is blank" do let(:xml_as_string) do <<-eos eos end it "renders a blank box to the pdf" do expect(File.exist?(output_pdf)).to be_falsey subject.lcnpj 0.80, 3.94, 1, 1, xml, "transporta/CNPJ" subject.render_file output_pdf expect("#{base_dir}document#lcnpj-blank.pdf").to be_same_file_as(output_pdf) end end end end