require 'spec_helper' describe USPSFlags do before(:all) do @valid_header = <<~SVG LTC Julian Fiander SVG @valid_body = <<~SVG This image is a registered trademark of United States Power Squadrons. http://www.usps.org/national/itcom/trademark.html SVG end before(:each) do @flag = USPSFlags.new end describe "constructor" do it "should update type" do @flag.type = "LtC" expect(@flag.type).to eql("LtC") end it "should update scale" do @flag.scale = 4 expect(@flag.scale).to eql(4) end it "should update field" do @flag.field = false expect(@flag.field).to eql(false) end it "should update trim" do @flag.trim = true expect(@flag.trim).to eql(true) end it "should correctly update svg_file" do @flag.svg_file = "#{$tmp_alt_flags_dir}/SVG/output.svg" expect(@flag.svg_file).to eql("#{$tmp_alt_flags_dir}/SVG/output.svg") end it "should correctly update png_file" do @flag.png_file = "#{$tmp_alt_flags_dir}/PNG/output.png" expect(@flag.png_file).to eql("#{$tmp_alt_flags_dir}/PNG/output.png") end describe "as configured" do before(:each) do @flag.type = "LtC" @flag.scale = 5 @flag.svg_file = "" end it "should construct and generate a flag with a valid header" do expect(@flag.svg).to include(@valid_header) end it "should construct and generate a flag with a valid body" do expect(@flag.svg).to include(@valid_body) end describe "png" do it "should raise PNGGenerationError without png_file set" do expect { @flag.png }.to raise_error(USPSFlags::Errors::PNGGenerationError, "A path must be set with png_file.") end it "should not raise PNGGenerationError with png_file set" do @flag.png_file = "#{$tmp_alt_flags_dir}/PNG/LtC.png" expect { @flag.png }.to_not raise_error(USPSFlags::Errors::PNGGenerationError) end end end end end