# frozen_string_literal: false require 'spec_helper' describe USPSFlags do before do @valid_header = <<~SVG LTC Julian Fiander SVG @valid_body = <<~SVG This image is a registered trademark of United States Power Squadrons. https://www.usps.org/images/secretary/itcom/trademark.pdf SVG @flag = described_class.new end describe 'constructor' do it 'updates type' do @flag.type = 'LtC' expect(@flag.type).to eql('LtC') end it 'updates scale' do @flag.scale = 4 expect(@flag.scale).to be(4) end it 'updates field' do @flag.field = false expect(@flag.field).to be(false) end it 'updates trim' do @flag.trim = true expect(@flag.trim).to be(true) end it 'correctlies 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 'correctlies 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 do @flag.type = 'LtC' @flag.scale = 5 @flag.svg_file = '' end it 'constructs and generate a flag with a valid header' do expect(@flag.svg).to include(@valid_header) end it 'constructs and generate a flag with a valid body' do expect(@flag.svg).to include(@valid_body) end describe 'png' do it 'raises PNGGenerationError without png_file set' do expect { @flag.png }.to raise_error( USPSFlags::Errors::PNGGenerationError, 'A path must be set with png_file.' ) end context 'with png_file set' do before do @flag.png_file = "#{$tmp_alt_flags_dir}/PNG/LtC.png" ::FileUtils.mkdir_p("#{$tmp_alt_flags_dir}/PNG/") end it 'does not raise PNGGenerationError with png_file set' do expect { @flag.png }.not_to raise_error end it 'returns the value of png_file' do expect(@flag.png).to eql("#{$tmp_alt_flags_dir}/PNG/LtC.png") end end end end end end