require 'spec_helper' describe BrDanfe::DanfeLib::NfceLib::TotalList do let(:base_dir) { './spec/fixtures/nfce/lib/' } let(:output_pdf) { "#{base_dir}output.pdf" } let(:pdf) { BrDanfe::DanfeLib::NfceLib::Document.new(8.cm, 5.cm) } let(:payment_xml) do <<~XML 01 10.00 02 15.30 05 66.70 XML end let(:xml_as_string) do <<~XML 104.00 12.00 92.00 #{payment_xml} XML end let(:xml_total_list) { BrDanfe::XML.new(xml_as_string) } subject { described_class.new pdf, xml_total_list } describe '#render' do before do subject.render File.delete(output_pdf) if File.exist?(output_pdf) end it 'renders the total list' do expect(File.exist?(output_pdf)).to be_falsey pdf.render_file output_pdf expect("#{base_dir}total_list#render.pdf").to have_same_content_of file: output_pdf end describe 'about totals' do let(:xml_as_string) do <<~XML 104.00 12.00 92.00 XML end it 'renders the totals' do expect(File.exist?(output_pdf)).to be_falsey pdf.render_file output_pdf expect("#{base_dir}total_list#render-totals.pdf").to have_same_content_of file: output_pdf end end describe 'about payment methods' do let(:payment_xml) do <<~XML 01 10.00 02 15.30 05 66.70 90 1.99 XML end it 'does not render the ""without payment"" payment method ' do expect(File.exist?(output_pdf)).to be_falsey pdf.render_file output_pdf expect("#{base_dir}total_list#render-without_payment.pdf").to have_same_content_of file: output_pdf end context 'when there are repeated payment methods' do let(:payment_xml) do <<~XML 01 10.00 01 30.00 02 25.50 02 26.50 XML end it 'renders grouped payment methods' do expect(File.exist?(output_pdf)).to be_falsey pdf.render_file output_pdf expect("#{base_dir}total_list#render-grouped_payment_methods.pdf").to have_same_content_of file: output_pdf end end context 'when there are only "without payment" payment methods' do let(:payment_xml) do <<~XML 90 10.00 90 15.30 90 66.70 XML end it 'does not render payment methods' do expect(File.exist?(output_pdf)).to be_falsey pdf.render_file output_pdf expect("#{base_dir}total_list#does_not_render-payment_methods.pdf").to have_same_content_of file: output_pdf end end end end end