#encoding: utf-8 require "spec_helper" describe BrDanfe::DanfeLib::Xprod do describe "#render" do context "when have FCI" do let(:xml_fci) do xml = <<-eos MONITOR DE ARCO ELETRICO 12232531-74B2-4FDD-87A6-CF0AD3E55386 eos Nokogiri::XML(xml) end subject { BrDanfe::DanfeLib::Xprod.new(xml_fci) } it "returns product + FCI" do expected = "MONITOR DE ARCO ELETRICO" expected += "\n" expected +="FCI: 12232531-74B2-4FDD-87A6-CF0AD3E55386" expect(subject.render).to eq expected end end context "when have ST" do let(:xml_st) do xml = <<-eos MONITOR DE ARCO ELETRICO 96.73 56.00 479.82 17.00 29.28 eos Nokogiri::XML(xml) end subject { BrDanfe::DanfeLib::Xprod.new(xml_st) } it "returns product + ST" do expected = "MONITOR DE ARCO ELETRICO" expected += "\n" expected += "ST: MVA: 56,00% * Alíq: 17,00% * BC: 479,82 * Vlr: 29,28" expect(subject.render).to eq expected end end context "when have infAdProd" do let(:xml_infAdProd) do xml = <<-eos MONITOR DE ARCO ELETRICO Informações adicionais do produto eos Nokogiri::XML(xml) end subject { BrDanfe::DanfeLib::Xprod.new(xml_infAdProd) } it "returns product + infAdProd" do expected = "MONITOR DE ARCO ELETRICO" expected += "\n" expected += "Informações adicionais do produto" expect(subject.render).to eq expected end end context "when have FCP" do let(:xml_fcp) do xml = <<-eos MONITOR DE ARCO ELETRICO 23.56 4.71 2.00 eos Nokogiri::XML(xml) end subject { BrDanfe::DanfeLib::Xprod.new(xml_fcp) } it "returns product + FCP" do expected = "MONITOR DE ARCO ELETRICO" expected += "\n" expected += "FCP: Alíq: 2,00% * Vlr: 4,71" expect(subject.render).to eq expected end end context "when have FCI + ST + infAdProd + FCP" do let(:xml_IFC_ST_infAdProd) do xml = <<-eos MONITOR DE ARCO ELETRICO 12232531-74B2-4FDD-87A6-CF0AD3E55386 96.73 56.00 479.82 17.00 29.28 4.71 2.00 Informações adicionais do produto eos Nokogiri::XML(xml) end subject { BrDanfe::DanfeLib::Xprod.new(xml_IFC_ST_infAdProd) } it "returns product + FCI + ST + infAdProd" do expected = "MONITOR DE ARCO ELETRICO" expected += "\n" expected += "Informações adicionais do produto" expected += "\n" expected +="FCI: 12232531-74B2-4FDD-87A6-CF0AD3E55386" expected += "\n" expected += "ST: MVA: 56,00% * Alíq: 17,00% * BC: 479,82 * Vlr: 29,28" expected += "\n" expected += "FCP: Alíq: 2,00% * Vlr: 4,71" expect(subject.render).to eq expected end end end end