require 'spec_helper' describe USPSFlags::Generate do describe "general features" do it "should generate a flag with the correct size" do expect(USPSFlags::Generate.svg("LtC", outfile: "")).to include( "width=\"1024pt\" height=\"682pt\" viewBox=\"0 0 3072 2048\"" ) end it "should generate a flag with the correct field" do expect(USPSFlags::Generate.svg("LtC", outfile: "")).to include( <<~SVG SVG ) end it "should generate a flag with the correct starting position" do expect(USPSFlags::Generate.svg("LtC", outfile: "")).to include("") expect(USPSFlags::Generate.svg("LtC", outfile: "")).to include("") end end describe "line flags" do it "should generate CC" do expect(USPSFlags::Generate.svg("CC", outfile: "")).to include("CC") end it "should generate VC" do expect(USPSFlags::Generate.svg("VC", outfile: "")).to include("VC") end it "should generate RC" do expect(USPSFlags::Generate.svg("RC", outfile: "")).to include("RC") end it "should generate StfC" do expect(USPSFlags::Generate.svg("StfC", outfile: "")).to include("STFC") end it "should generate DC" do expect(USPSFlags::Generate.svg("DC", outfile: "")).to include("DC") end it "should generate DLtC" do expect(USPSFlags::Generate.svg("DLtC", outfile: "")).to include("DLTC") end it "should generate D1Lt" do expect(USPSFlags::Generate.svg("D1Lt", outfile: "")).to include("D1LT") end it "should generate DLt" do expect(USPSFlags::Generate.svg("DLt", outfile: "")).to include("DLT") end it "should generate Cdr" do expect(USPSFlags::Generate.svg("Cdr", outfile: "")).to include("CDR") end it "should generate LtC" do expect(USPSFlags::Generate.svg("LtC", outfile: "")).to include("LTC") end it "should generate 1Lt" do expect(USPSFlags::Generate.svg("1Lt", outfile: "")).to include("1LT") end it "should generate Lt" do expect(USPSFlags::Generate.svg("Lt", outfile: "")).to include("LT") end end describe "special flags" do it "should generate PortCap" do expect(USPSFlags::Generate.svg("PortCap", outfile: "")).to include("PORTCAP") end it "should generate FleetCap" do expect(USPSFlags::Generate.svg("FleetCap", outfile: "")).to include("FLEETCAP") end it "should generate DAide" do expect(USPSFlags::Generate.svg("DAide", outfile: "")).to include("DAIDE") end it "should generate NAide" do expect(USPSFlags::Generate.svg("NAide", outfile: "")).to include("NAIDE") end it "should generate FLt" do expect(USPSFlags::Generate.svg("FLt", outfile: "")).to include("FLT") end it "should generate DFLt" do expect(USPSFlags::Generate.svg("DFLt", outfile: "")).to include("DFLT") end it "should generate NFLt" do expect(USPSFlags::Generate.svg("NFLt", outfile: "")).to include("NFLT") end end describe "pennants" do it "should generate the cruise pennant" do expect(USPSFlags::Generate.svg("Cruise", outfile: "")).to include("Cruise Pennant") end it "should generate the officer-in-charge pennant" do expect(USPSFlags::Generate.svg("OIC", outfile: "")).to include("Officer-in-Charge Pennant") end end describe "other flags" do it "should generate US" do expect(USPSFlags::Generate.svg("US", outfile: "")).to include("US Ensign") end it "should generate USPS Ensign" do expect(USPSFlags::Generate.svg("Ensign", outfile: "")).to include("USPS Ensign") end it "should generate the USPS Wheel logo" do expect(USPSFlags::Generate.svg("Wheel", outfile: "")).to include("USPS Ensign Wheel") end end describe "trident specifications" do it "should generate the trident specification sheet" do expect(USPSFlags::Generate.spec(outfile: "")).to include("USPS Trident Specifications") end it "should generate the trident specification sheet with a fractional field size" do expect(USPSFlags::Generate.spec(outfile: "", fly: 23.5)).to include("USPS Trident Specifications") end end describe "png" do it "should raise PNGGenerationError without an outfile" do expect { USPSFlags::Generate.png(USPSFlags::Generate.svg("LtC", outfile: ""), outfile: "") }.to raise_error(USPSFlags::Errors::PNGGenerationError) end it "should not raise PNGGenerationError when correctly configured" do expect { USPSFlags::Generate.png(USPSFlags::Generate.svg("LtC", outfile: ""), outfile: "lib/output/PNG/LTC.png") }.to_not raise_error(USPSFlags::Errors::PNGGenerationError) end end describe "without an outfile set" do it "should print SVG data to the console" do expect(STDOUT).to receive(:puts).with(USPSFlags::Generate.svg("Lt", outfile: ""), "\n") USPSFlags::Generate.svg("Lt") end end describe "static files" do it "should raise USPSFlags::Errors::StaticFilesGenerationError when not given any true arguments" do expect { USPSFlags::Generate.all(svg: false, png: false, zips: false, reset: false) }.to raise_error( USPSFlags::Errors::StaticFilesGenerationError, "At least one argument switch must be true out of [svg, png, zips, reset]." ) end it "should raise USPSFlags::Errors::ZipGenerationError when not given any true arguments" do expect { USPSFlags::Generate.zips(svg: false, png: false) }.to raise_error( USPSFlags::Errors::ZipGenerationError, "At least one argument switch must be true out of [svg, png]." ) end it "should not raise an error while generating all static files" do png_dir = "#{USPSFlags.configuration.flags_dir}/PNG" ::FileUtils.cp("spec/assets/1LT.thumb.png", "#{png_dir}/insignia/1LT.thumb.png") ::FileUtils.cp("spec/assets/LT.png", "#{png_dir}/insignia/LT.png") ::FileUtils.cp("spec/assets/FLT.png", "#{png_dir}/FLT.png") expect { USPSFlags::Generate.all(reset: false) }.to_not raise_error # (USPSFlags::Errors::StaticFilesGenerationError) end it "should have generated the correct log output" do correct_log_pattern = <<~LOG Flag | SVG | PNG | Run time --------------------------------------- PLTC | S- | F-H-K-D-T- | .*? s PC | S- | F-H-K-D-T- | .*? s 1LT | SI | FIH\\+K\\+DiT\\. | .*? s LTC | SI | FIHiKiDiTi | .*? s CDR | SI | FIHiKiDiTi | .*? s PORTCAP | SI | FIH\\+K\\+DiTi | .*? s FLEETCAP | SI | FIH\\+KiDiTi | .*? s LT | SI | F\\.H\\+K\\+DiTi | .*? s FLT | SI | \\.IH\\+K\\+DiTi | .*? s PDLTC | S- | F-H-K-D-T- | .*? s PDC | S- | F-H-K-D-T- | .*? s D1LT | SI | FIH\\+K\\+DiTi | .*? s DLTC | SI | FIHiKiDiTi | .*? s DC | SI | FIHiKiDiTi | .*? s DLT | SI | FIH\\+K\\+DiTi | .*? s DAIDE | SI | FIH\\+KiDiTi | .*? s DFLT | SI | FIHiKiDiTi | .*? s PSTFC | S- | F-H-K-D-T- | .*? s PRC | S- | F-H-K-D-T- | .*? s PVC | S- | F-H-K-D-T- | .*? s PCC | S- | F-H-K-D-T- | .*? s NAIDE | SI | FIH\\+KiDiTi | .*? s NFLT | SI | FIHiKiDiTi | .*? s STFC | SI | FIH\\+K\\+DiTi | .*? s RC | SI | FIH\\+K\\+DiTi | .*? s VC | SI | FIHiKiDiTi | .*? s CC | SI | FIHiKiDiTi | .*? s CRUISE | S- | F-H-K-D-T- | .*? s OIC | S- | F-H-K-D-T- | .*? s ENSIGN | S- | F-H-K-D-T- | .*? s WHEEL | S- | F-H-K-D-T- | .*? s US | S- | F-H-K-D-T- | .*? s Generated SVG Zip Generated PNG Zip LOG log_contents = ::File.read("#{USPSFlags.configuration.log_path}/flag.log") expect(log_contents).to match(Regexp.new(correct_log_pattern)) end it "should not raise an error while clearing all static files" do expect { USPSFlags::Generate.all(svg: false, png: false, zips: false, reset: true) }.to_not raise_error # (USPSFlags::Errors::StaticFilesGenerationError) end it "should not raise an error while generating zip files" do expect { USPSFlags::Generate.zips }.to_not raise_error # (USPSFlags::Errors::ZipGenerationError) end end end