diff --git a/.simplecov b/.simplecov index 70bc9c9..b401c44 100644 --- a/.simplecov +++ b/.simplecov @@ -1,19 +1,15 @@ # frozen_string_literal: true -require 'simplecov_json_formatter' -require 'simplecov-console' +formatters = SimpleCov::Formatter.from_env(ENV) -formatters = [ - SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::JSONFormatter -] - -# rubocop:disable Style/IfUnlessModifier if RSpec.configuration.files_to_run.length > 1 + require "simplecov-console" + formatters << SimpleCov::Formatter::Console end -# rubocop:enable Style/IfUnlessModifier SimpleCov.start do + enable_coverage :branch + formatter SimpleCov::Formatter::MultiFormatter.new(formatters) end diff --git a/Gemfile b/Gemfile index 43d0926..d59a9d6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,17 +1,17 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" -# Specify your gem's dependencies in svgeez.gemspec +# Specify your gem"s dependencies in svgeez.gemspec gemspec -gem 'debug' -gem 'rake' -gem 'rspec' -gem 'rubocop' -gem 'rubocop-packaging' -gem 'rubocop-performance' -gem 'rubocop-rake' -gem 'rubocop-rspec' -gem 'simplecov' -gem 'simplecov-console' +gem "debug" +gem "rake" +gem "rspec" +gem "rubocop" +gem "rubocop-packaging" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "simplecov" +gem "simplecov-console" diff --git a/Rakefile b/Rakefile index dd41dec..88546c3 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,7 @@ # frozen_string_literal: true -require 'bundler/gem_tasks' - -require 'rspec/core/rake_task' +require "bundler/gem_tasks" +require "rspec/core/rake_task" RSpec::Core::RakeTask.new diff --git a/bin/console b/bin/console index b62b468..7a10fa3 100755 --- a/bin/console +++ b/bin/console @@ -1,15 +1,15 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require 'bundler/setup' -require 'svgeez' +require "bundler/setup" +require "svgeez" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. # (If you use this, don't forget to add pry to your Gemfile!) -# require 'pry' +# require "pry" # Pry.start -require 'irb' +require "irb" IRB.start(__FILE__) diff --git a/exe/svgeez b/exe/svgeez index 7b6dd48..c92751d 100755 --- a/exe/svgeez +++ b/exe/svgeez @@ -1,16 +1,15 @@ #!/usr/bin/env ruby - # frozen_string_literal: true -$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') +$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib") -require 'mercenary' -require 'svgeez' +require "mercenary" +require "svgeez" Mercenary.program(:svgeez) do |program| program.version Svgeez::VERSION - program.description 'Generate an SVG sprite from a folder of SVG icons.' - program.syntax 'svgeez [options]' + program.description "Generate an SVG sprite from a folder of SVG icons." + program.syntax "svgeez [options]" Svgeez::Command.subclasses.each do |command| command.init_with_program(program) diff --git a/lib/svgeez.rb b/lib/svgeez.rb index 39f4ffe..7e88266 100644 --- a/lib/svgeez.rb +++ b/lib/svgeez.rb @@ -1,26 +1,26 @@ # frozen_string_literal: true -require 'fileutils' -require 'logger' -require 'mkmf' -require 'securerandom' +require "fileutils" +require "logger" +require "mkmf" +require "securerandom" -require 'listen' -require 'mercenary' +require "listen" +require "mercenary" -require_relative 'svgeez/version' +require_relative "svgeez/version" -require_relative 'svgeez/command' -require_relative 'svgeez/commands/build' -require_relative 'svgeez/commands/watch' +require_relative "svgeez/command" +require_relative "svgeez/commands/build" +require_relative "svgeez/commands/watch" -require_relative 'svgeez/elements/svg_element' -require_relative 'svgeez/elements/symbol_element' +require_relative "svgeez/elements/svg_element" +require_relative "svgeez/elements/symbol_element" -require_relative 'svgeez/builder' -require_relative 'svgeez/destination' -require_relative 'svgeez/optimizer' -require_relative 'svgeez/source' +require_relative "svgeez/builder" +require_relative "svgeez/destination" +require_relative "svgeez/optimizer" +require_relative "svgeez/source" module Svgeez def self.logger diff --git a/lib/svgeez/builder.rb b/lib/svgeez/builder.rb index 62a1256..627d4a8 100644 --- a/lib/svgeez/builder.rb +++ b/lib/svgeez/builder.rb @@ -3,16 +3,16 @@ module Svgeez class Builder SOURCE_IS_DESTINATION_MESSAGE = "Setting `source` and `destination` to the same path isn't allowed!" - SOURCE_DOES_NOT_EXIST = 'Provided `source` folder does not exist.' - NO_SVGS_IN_SOURCE_MESSAGE = 'No SVGs were found in `source` folder.' + SOURCE_DOES_NOT_EXIST = "Provided `source` folder does not exist." + NO_SVGS_IN_SOURCE_MESSAGE = "No SVGs were found in `source` folder." attr_reader :source, :destination, :prefix def initialize(options = {}) @source = Source.new(options) @destination = Destination.new(options) - @svgo = options.fetch('svgo', false) - @prefix = options.fetch('prefix', @destination.file_id) + @svgo = options.fetch("svgo", false) + @prefix = options.fetch("prefix", @destination.file_id) raise SOURCE_IS_DESTINATION_MESSAGE if source_is_destination? raise SOURCE_DOES_NOT_EXIST unless source_exists? @@ -21,7 +21,6 @@ def initialize(options = {}) exit end - # rubocop:disable Metrics/AbcSize def build raise NO_SVGS_IN_SOURCE_MESSAGE if source_is_empty? @@ -37,7 +36,6 @@ def build rescue RuntimeError => e logger.warn e.message end - # rubocop:enable Metrics/AbcSize private @@ -45,7 +43,7 @@ def destination_file_contents file_contents = Elements::SvgElement.new(source, destination, prefix).build file_contents = Optimizer.new.optimize(file_contents) if @svgo - file_contents.insert(4, ' style="display: none;"') + file_contents.insert(4, %( style="display: none;")) end def destination_file_path diff --git a/lib/svgeez/command.rb b/lib/svgeez/command.rb index 4dd61dd..c82b31f 100644 --- a/lib/svgeez/command.rb +++ b/lib/svgeez/command.rb @@ -13,7 +13,7 @@ def inherited(base) end def init_with_program(program) - program.command(name.split('::').last.downcase.to_sym) do |command| + program.command(name.split("::").last.downcase.to_sym) do |command| command.description command_description command.syntax command_syntax @@ -31,10 +31,10 @@ def add_actions(command) end def add_options(command) - command.option 'source', '-s', '--source [FOLDER]', 'Source folder (defaults to ./_svgeez)' - command.option 'destination', '-d', '--destination [OUTPUT]', 'Destination file or folder (defaults to ./svgeez.svg)' - command.option 'prefix', '-p', '--prefix [PREFIX]', 'Custom Prefix for icon id (defaults to destination filename)' - command.option 'svgo', '--with-svgo', 'Optimize source SVGs with SVGO before sprite generation (non-destructive)' + command.option "source", "-s", "--source [FOLDER]", "Source folder (defaults to ./_svgeez)" + command.option "destination", "-d", "--destination [OUTPUT]", "Destination file or folder (defaults to ./svgeez.svg)" + command.option "prefix", "-p", "--prefix [PREFIX]", "Custom Prefix for icon id (defaults to destination filename)" + command.option "svgo", "--with-svgo", "Optimize source SVGs with SVGO before sprite generation (non-destructive)" end end end diff --git a/lib/svgeez/commands/build.rb b/lib/svgeez/commands/build.rb index 61cf372..1ac9717 100644 --- a/lib/svgeez/commands/build.rb +++ b/lib/svgeez/commands/build.rb @@ -15,11 +15,11 @@ def command_action(options) end def command_description - 'Builds an SVG sprite from a folder of SVG icons' + "Builds an SVG sprite from a folder of SVG icons" end def command_syntax - 'build [options]' + "build [options]" end end end diff --git a/lib/svgeez/commands/watch.rb b/lib/svgeez/commands/watch.rb index 830d7bc..2449933 100644 --- a/lib/svgeez/commands/watch.rb +++ b/lib/svgeez/commands/watch.rb @@ -13,7 +13,7 @@ def process(options) Listen.to(folder_path, only: /\.svg\z/) { builder.build }.start sleep rescue Interrupt - Svgeez.logger.info 'Quitting svgeez...' + Svgeez.logger.info "Quitting svgeez..." end private @@ -24,11 +24,11 @@ def command_action(options) end def command_description - 'Watches a folder of SVG icons for changes' + "Watches a folder of SVG icons for changes" end def command_syntax - 'watch [options]' + "watch [options]" end end end diff --git a/lib/svgeez/destination.rb b/lib/svgeez/destination.rb index 2004a6b..a4e7d10 100644 --- a/lib/svgeez/destination.rb +++ b/lib/svgeez/destination.rb @@ -2,19 +2,19 @@ module Svgeez class Destination - DEFAULT_DESTINATION_FILE_NAME = 'svgeez.svg' + DEFAULT_DESTINATION_FILE_NAME = "svgeez.svg" def initialize(options = {}) - @destination = File.expand_path(options.fetch('destination', "./#{DEFAULT_DESTINATION_FILE_NAME}")) + @destination = File.expand_path(options.fetch("destination", "./#{DEFAULT_DESTINATION_FILE_NAME}")) end def file_id - @file_id ||= File.basename(file_name, '.svg').tr(' ', '-') + @file_id ||= File.basename(file_name, ".svg").tr(" ", "-") end def file_name @file_name ||= - if @destination.end_with?('.svg') + if @destination.end_with?(".svg") File.split(@destination)[1] else DEFAULT_DESTINATION_FILE_NAME @@ -27,7 +27,7 @@ def file_path def folder_path @folder_path ||= - if @destination.end_with?('.svg') + if @destination.end_with?(".svg") File.split(@destination)[0] else @destination diff --git a/lib/svgeez/elements/symbol_element.rb b/lib/svgeez/elements/symbol_element.rb index 9e9307e..71361a7 100644 --- a/lib/svgeez/elements/symbol_element.rb +++ b/lib/svgeez/elements/symbol_element.rb @@ -10,7 +10,7 @@ def initialize(file_path, file_id) def build File.read(@file_path).match(%r{^.*?)>(?.*?)}m) do |matches| - %(#{element_contents(matches[:content])}) + %(#{element_contents(matches[:content])}) end end @@ -19,8 +19,8 @@ def build def element_attributes(attributes) attrs = attributes.scan(/(?:viewBox|xmlns:.+?)=".*?"/m) id_prefix = @file_id - id_suffix = File.basename(@file_path, '.svg').gsub(/['"\s]/, '-') - id_attribute = [id_prefix, id_suffix].reject(&:empty?).join('-') + id_suffix = File.basename(@file_path, ".svg").gsub(/['"\s]/, "-") + id_attribute = [id_prefix, id_suffix].reject(&:empty?).join("-") attrs << %(id="#{id_attribute}") end diff --git a/lib/svgeez/optimizer.rb b/lib/svgeez/optimizer.rb index 7cb7c46..6699914 100644 --- a/lib/svgeez/optimizer.rb +++ b/lib/svgeez/optimizer.rb @@ -2,9 +2,9 @@ module Svgeez class Optimizer - SVGO_VERSION = '1.3.2' + SVGO_VERSION = "1.3.2" SVGO_VERSION_MESSAGE = "svgeez relies on SVGO #{SVGO_VERSION}. Continuing with standard sprite generation..." - SVGO_NOT_INSTALLED = 'Unable to find `svgo` in your PATH. Continuing with standard sprite generation...' + SVGO_NOT_INSTALLED = "Unable to find `svgo` in your PATH. Continuing with standard sprite generation..." def optimize(file_contents) raise SVGO_NOT_INSTALLED unless installed? @@ -18,7 +18,7 @@ def optimize(file_contents) private def installed? - @installed ||= find_executable0('svgo') + @installed ||= find_executable0("svgo") end def logger diff --git a/lib/svgeez/source.rb b/lib/svgeez/source.rb index adf70fa..6fc3e08 100644 --- a/lib/svgeez/source.rb +++ b/lib/svgeez/source.rb @@ -2,12 +2,12 @@ module Svgeez class Source - DEFAULT_INPUT_FOLDER_PATH = './_svgeez' + DEFAULT_INPUT_FOLDER_PATH = "./_svgeez" attr_reader :folder_path def initialize(options = {}) - @folder_path = File.expand_path(options.fetch('source', DEFAULT_INPUT_FOLDER_PATH)) + @folder_path = File.expand_path(options.fetch("source", DEFAULT_INPUT_FOLDER_PATH)) end def file_paths @@ -17,7 +17,7 @@ def file_paths private def file_paths_pattern - @file_paths_pattern ||= File.join(folder_path, '*.svg') + @file_paths_pattern ||= File.join(folder_path, "*.svg") end end end diff --git a/lib/svgeez/version.rb b/lib/svgeez/version.rb index 2611387..ae5724d 100644 --- a/lib/svgeez/version.rb +++ b/lib/svgeez/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Svgeez - VERSION = '4.1.0' + VERSION = "4.1.0" end diff --git a/spec/lib/svgeez/builder_build_spec.rb b/spec/lib/svgeez/builder_build_spec.rb index 1fe9332..16b8505 100644 --- a/spec/lib/svgeez/builder_build_spec.rb +++ b/spec/lib/svgeez/builder_build_spec.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -RSpec.describe Svgeez::Builder, '#build' do +RSpec.describe Svgeez::Builder, "#build" do let(:file) { class_double(File) } let(:logger) { Svgeez.logger } let(:error_message) { "Setting `source` and `destination` to the same path isn't allowed!" } - let(:warning_message) { 'No SVGs were found in `source` folder.' } + let(:warning_message) { "No SVGs were found in `source` folder." } before do allow(File).to receive(:directory?).and_return(true) @@ -14,22 +14,22 @@ allow(logger).to receive(:warn) end - context 'when @source does not exist' do + context "when @source does not exist" do before do allow(File).to receive(:directory?).and_return(false) end - it 'logs an error' do + it "logs an error" do expect { described_class.new.build }.to raise_error(SystemExit) - expect(logger).to have_received(:error).with('Provided `source` folder does not exist.') + expect(logger).to have_received(:error).with("Provided `source` folder does not exist.") end end - context 'when @source and @destination are the same' do - it 'logs an error' do + context "when @source and @destination are the same" do + it "logs an error" do builder = described_class.new( - 'source' => './foo', - 'destination' => './foo' + "source" => "./foo", + "destination" => "./foo" ) expect { builder.build }.to raise_error(SystemExit) @@ -37,11 +37,11 @@ end end - context 'when @destination is nested within @source' do - it 'logs an error' do + context "when @destination is nested within @source" do + it "logs an error" do builder = described_class.new( - 'source' => './foo', - 'destination' => './foo/bar.svg' + "source" => "./foo", + "destination" => "./foo/bar.svg" ) expect { builder.build }.to raise_error(SystemExit) @@ -49,22 +49,22 @@ end end - context 'when @source contains no SVG files' do - it 'logs a warning' do + context "when @source contains no SVG files" do + it "logs a warning" do described_class.new.build expect(logger).to have_received(:warn).with(warning_message) end end - context 'when @source contains SVG files' do + context "when @source contains SVG files" do let(:source) { instance_double(Svgeez::Source) } - let(:source_folder_path) { './spec/fixtures/icons' } + let(:source_folder_path) { "./spec/fixtures/icons" } before do allow(FileUtils).to receive(:mkdir_p) allow(File).to receive(:open).and_yield(file) - allow(SecureRandom).to receive(:uuid).and_return('1234-abcd-5678-efgh') + allow(SecureRandom).to receive(:uuid).and_return("1234-abcd-5678-efgh") allow(Svgeez::Source).to receive(:new).and_return(source) @@ -76,46 +76,46 @@ allow(source).to receive(:folder_path).and_return(File.expand_path(source_folder_path)) end - context 'when @svgo is not specified' do - it 'writes a file' do + context "when @svgo is not specified" do + it "writes a file" do described_class.new( - 'source' => source_folder_path, - 'destination' => './spec/fixtures/icons.svg' + "source" => source_folder_path, + "destination" => "./spec/fixtures/icons.svg" ).build - expect(file).to have_received(:write).with(File.read('./spec/fixtures/icons.svg')) + expect(file).to have_received(:write).with(File.read("./spec/fixtures/icons.svg")) expect(logger).to have_received(:info).exactly(:twice) end end - context 'when @svgo is specified' do - it 'writes a file' do + context "when @svgo is specified" do + it "writes a file" do described_class.new( - 'source' => source_folder_path, - 'destination' => './spec/fixtures/icons-svgo.svg', - 'svgo' => true + "source" => source_folder_path, + "destination" => "./spec/fixtures/icons-svgo.svg", + "svgo" => true ).build - expect(file).to have_received(:write).with(%(#{File.read('./spec/fixtures/icons-svgo.svg')}\n)) + expect(file).to have_received(:write).with(%(#{File.read("./spec/fixtures/icons-svgo.svg")}\n)) expect(logger).to have_received(:info).exactly(:twice) end end end - describe '--prefix option' do - context 'when --prefix option is not used' do - it 'assigns destination file_id as @prefix' do + describe "--prefix option" do + context "when --prefix option is not used" do + it "assigns destination file_id as @prefix" do builder = described_class.new expect(builder.prefix).to eq(builder.destination.file_id) end end - context 'when --prefix option is used' do - it 'assigns provided value as @prefix' do - builder = described_class.new('prefix' => 'icon') + context "when --prefix option is used" do + it "assigns provided value as @prefix" do + builder = described_class.new("prefix" => "icon") - expect(builder.prefix).to eq('icon') + expect(builder.prefix).to eq("icon") end end end diff --git a/spec/lib/svgeez/commands/build_init_with_program_spec.rb b/spec/lib/svgeez/commands/build_init_with_program_spec.rb index 2012e96..5ebf1dd 100644 --- a/spec/lib/svgeez/commands/build_init_with_program_spec.rb +++ b/spec/lib/svgeez/commands/build_init_with_program_spec.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -RSpec.describe Svgeez::Commands::Build, '.init_with_program' do +RSpec.describe Svgeez::Commands::Build, ".init_with_program" do let(:program) { Mercenary::Program.new(:svgeez) } let(:command) { described_class.init_with_program(program) } - it 'sets a description' do - expect(command.description).to eq('Builds an SVG sprite from a folder of SVG icons') + it "sets a description" do + expect(command.description).to eq("Builds an SVG sprite from a folder of SVG icons") end - it 'sets a syntax' do - expect(command.syntax).to eq('svgeez build [options]') + it "sets a syntax" do + expect(command.syntax).to eq("svgeez build [options]") end end diff --git a/spec/lib/svgeez/commands/watch_init_with_program_spec.rb b/spec/lib/svgeez/commands/watch_init_with_program_spec.rb index 176c05a..6dd468e 100644 --- a/spec/lib/svgeez/commands/watch_init_with_program_spec.rb +++ b/spec/lib/svgeez/commands/watch_init_with_program_spec.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -RSpec.describe Svgeez::Commands::Watch, '.init_with_program' do +RSpec.describe Svgeez::Commands::Watch, ".init_with_program" do let(:program) { Mercenary::Program.new(:svgeez) } let(:command) { described_class.init_with_program(program) } - it 'sets a description' do - expect(command.description).to eq('Watches a folder of SVG icons for changes') + it "sets a description" do + expect(command.description).to eq("Watches a folder of SVG icons for changes") end - it 'sets a syntax' do - expect(command.syntax).to eq('svgeez watch [options]') + it "sets a syntax" do + expect(command.syntax).to eq("svgeez watch [options]") end end diff --git a/spec/lib/svgeez/destination_file_id_spec.rb b/spec/lib/svgeez/destination_file_id_spec.rb index 0e3321e..7a05df1 100644 --- a/spec/lib/svgeez/destination_file_id_spec.rb +++ b/spec/lib/svgeez/destination_file_id_spec.rb @@ -1,23 +1,23 @@ # frozen_string_literal: true -RSpec.describe Svgeez::Destination, '#file_id' do - context 'when @destination is not specified' do +RSpec.describe Svgeez::Destination, "#file_id" do + context "when @destination is not specified" do let(:destination) { described_class.new } - it 'returns the default file ID' do - expect(destination.file_id).to eq('svgeez') + it "returns the default file ID" do + expect(destination.file_id).to eq("svgeez") end end - context 'when @destination is specified' do + context "when @destination is specified" do let(:destination) do described_class.new( - 'destination' => './foo.svg' + "destination" => "./foo.svg" ) end - it 'returns the specified file ID' do - expect(destination.file_id).to eq('foo') + it "returns the specified file ID" do + expect(destination.file_id).to eq("foo") end end end diff --git a/spec/lib/svgeez/destination_file_name_spec.rb b/spec/lib/svgeez/destination_file_name_spec.rb index 9b5fe81..d1b9117 100644 --- a/spec/lib/svgeez/destination_file_name_spec.rb +++ b/spec/lib/svgeez/destination_file_name_spec.rb @@ -1,36 +1,36 @@ # frozen_string_literal: true -RSpec.describe Svgeez::Destination, '#file_name' do - context 'when @destination is not specified' do +RSpec.describe Svgeez::Destination, "#file_name" do + context "when @destination is not specified" do let(:destination) { described_class.new } - it 'returns the default file name' do - expect(destination.file_name).to eq('svgeez.svg') + it "returns the default file name" do + expect(destination.file_name).to eq("svgeez.svg") end end - context 'when @destination is specified' do - context 'when @destination is a folder path' do + context "when @destination is specified" do + context "when @destination is a folder path" do let(:destination) do described_class.new( - 'destination' => './foo' + "destination" => "./foo" ) end - it 'returns the default file name' do - expect(destination.file_name).to eq('svgeez.svg') + it "returns the default file name" do + expect(destination.file_name).to eq("svgeez.svg") end end - context 'when @destination is a file name' do + context "when @destination is a file name" do let(:destination) do described_class.new( - 'destination' => './foo.svg' + "destination" => "./foo.svg" ) end - it 'returns the specified file name' do - expect(destination.file_name).to eq('foo.svg') + it "returns the specified file name" do + expect(destination.file_name).to eq("foo.svg") end end end diff --git a/spec/lib/svgeez/destination_file_path_spec.rb b/spec/lib/svgeez/destination_file_path_spec.rb index 6b316df..4987482 100644 --- a/spec/lib/svgeez/destination_file_path_spec.rb +++ b/spec/lib/svgeez/destination_file_path_spec.rb @@ -1,36 +1,36 @@ # frozen_string_literal: true -RSpec.describe Svgeez::Destination, '#file_path' do - context 'when @destination is not specified' do +RSpec.describe Svgeez::Destination, "#file_path" do + context "when @destination is not specified" do let(:destination) { described_class.new } - it 'returns the default file path' do - expect(destination.file_path).to eq(File.expand_path('./svgeez.svg')) + it "returns the default file path" do + expect(destination.file_path).to eq(File.expand_path("./svgeez.svg")) end end - context 'when @destination is specified' do - context 'when @destination is a folder path' do + context "when @destination is specified" do + context "when @destination is a folder path" do let(:destination) do described_class.new( - 'destination' => './foo' + "destination" => "./foo" ) end - it 'returns the specified file path' do - expect(destination.file_path).to eq(File.expand_path('./foo/svgeez.svg')) + it "returns the specified file path" do + expect(destination.file_path).to eq(File.expand_path("./foo/svgeez.svg")) end end - context 'when @destination is a file name' do + context "when @destination is a file name" do let(:destination) do described_class.new( - 'destination' => './foo/bar.svg' + "destination" => "./foo/bar.svg" ) end - it 'returns the specified file path' do - expect(destination.file_path).to eq(File.expand_path('./foo/bar.svg')) + it "returns the specified file path" do + expect(destination.file_path).to eq(File.expand_path("./foo/bar.svg")) end end end diff --git a/spec/lib/svgeez/destination_folder_path_spec.rb b/spec/lib/svgeez/destination_folder_path_spec.rb index 4d67a54..6423c9d 100644 --- a/spec/lib/svgeez/destination_folder_path_spec.rb +++ b/spec/lib/svgeez/destination_folder_path_spec.rb @@ -1,36 +1,36 @@ # frozen_string_literal: true -RSpec.describe Svgeez::Destination, '#folder_path' do - context 'when @destination is not specified' do +RSpec.describe Svgeez::Destination, "#folder_path" do + context "when @destination is not specified" do let(:destination) { described_class.new } - it 'returns the default folder path' do - expect(destination.folder_path).to eq(File.expand_path('.')) + it "returns the default folder path" do + expect(destination.folder_path).to eq(File.expand_path(".")) end end - context 'when @destination is specified' do - context 'when @destination is a folder path' do + context "when @destination is specified" do + context "when @destination is a folder path" do let(:destination) do described_class.new( - 'destination' => './foo' + "destination" => "./foo" ) end - it 'returns the specified folder path' do - expect(destination.folder_path).to eq(File.expand_path('./foo')) + it "returns the specified folder path" do + expect(destination.folder_path).to eq(File.expand_path("./foo")) end end - context 'when @destination is a file name' do + context "when @destination is a file name" do let(:destination) do described_class.new( - 'destination' => './foo/bar.svg' + "destination" => "./foo/bar.svg" ) end - it 'returns the specified folder path' do - expect(destination.folder_path).to eq(File.expand_path('./foo')) + it "returns the specified folder path" do + expect(destination.folder_path).to eq(File.expand_path("./foo")) end end end diff --git a/spec/lib/svgeez/elements/svg_element_build_spec.rb b/spec/lib/svgeez/elements/svg_element_build_spec.rb index d5bb2b8..7d6816e 100644 --- a/spec/lib/svgeez/elements/svg_element_build_spec.rb +++ b/spec/lib/svgeez/elements/svg_element_build_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Svgeez::Elements::SvgElement, '#build' do +RSpec.describe Svgeez::Elements::SvgElement, "#build" do let(:source) { instance_double(Svgeez::Source) } let(:destination) { instance_double(Svgeez::Destination) } let(:symbol_element) { instance_double(Svgeez::Elements::SymbolElement) } @@ -12,12 +12,12 @@ allow(Svgeez::Destination).to receive(:new).and_return(destination) allow(Svgeez::Elements::SymbolElement).to receive(:new).and_return(symbol_element) - allow(source).to receive(:file_paths).and_return([File.expand_path('./spec/fixtures/icons/skull.svg')]) - allow(destination).to receive(:file_id).and_return('foo') - allow(symbol_element).to receive(:build).and_return('') + allow(source).to receive(:file_paths).and_return([File.expand_path("./spec/fixtures/icons/skull.svg")]) + allow(destination).to receive(:file_id).and_return("foo") + allow(symbol_element).to receive(:build).and_return("") end - it 'returns a string' do + it "returns a string" do expect(svg_element.build).to eq(%()) end end diff --git a/spec/lib/svgeez/elements/symbol_element_build_spec.rb b/spec/lib/svgeez/elements/symbol_element_build_spec.rb index b5dc349..a1d74f9 100644 --- a/spec/lib/svgeez/elements/symbol_element_build_spec.rb +++ b/spec/lib/svgeez/elements/symbol_element_build_spec.rb @@ -1,29 +1,29 @@ # frozen_string_literal: true -RSpec.describe Svgeez::Elements::SymbolElement, '#build' do - let(:uuid) { '1234-abcd-5678-efgh' } - let(:file_path) { File.expand_path('./spec/fixtures/icons/facebook.svg') } - let(:file_id) { 'foo' } +RSpec.describe Svgeez::Elements::SymbolElement, "#build" do + let(:uuid) { "1234-abcd-5678-efgh" } + let(:file_path) { File.expand_path("./spec/fixtures/icons/facebook.svg") } + let(:file_id) { "foo" } before do allow(SecureRandom).to receive(:uuid).and_return(uuid) end - it 'returns a string' do + it "returns a string" do symbol_element = described_class.new(file_path, file_id) expect(symbol_element.build).to eq(%(\n\n\s\s\n\n\n\s\s\n\s\s\n\s\s\s\s\n\s\s\n\n)) end - context 'when file_id is blank' do - it 'only uses filename of file_path as id attribute' do - symbol_element = described_class.new(file_path, '') + context "when file_id is blank" do + it "only uses filename of file_path as id attribute" do + symbol_element = described_class.new(file_path, "") expect(symbol_element.build).to match(/id="facebook"/) end end - context 'when file_id is provided' do - it 'includes file_id in id attribute' do - symbol_element = described_class.new(file_path, 'icon') + context "when file_id is provided" do + it "includes file_id in id attribute" do + symbol_element = described_class.new(file_path, "icon") expect(symbol_element.build).to match(/id="icon-facebook"/) end end diff --git a/spec/lib/svgeez/optimizer_optimize_spec.rb b/spec/lib/svgeez/optimizer_optimize_spec.rb index ab53ece..f0c35bd 100644 --- a/spec/lib/svgeez/optimizer_optimize_spec.rb +++ b/spec/lib/svgeez/optimizer_optimize_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Svgeez::Optimizer, '#optimize' do +RSpec.describe Svgeez::Optimizer, "#optimize" do let(:logger) { Svgeez.logger } let(:optimizer) { described_class.new } @@ -10,40 +10,40 @@ allow(logger).to receive(:warn) end - context 'when SVGO executable is not found' do - let(:warning_message) { 'Unable to find `svgo` in your PATH. Continuing with standard sprite generation...' } + context "when SVGO executable is not found" do + let(:warning_message) { "Unable to find `svgo` in your PATH. Continuing with standard sprite generation..." } before do allow(optimizer).to receive(:installed?).and_return(nil) end - it 'logs a warning' do - optimizer.optimize('') + it "logs a warning" do + optimizer.optimize("") expect(logger).to have_received(:warn).with(warning_message) end end - context 'when SVGO executable is found' do - context 'when SVGO version is not supported' do - let(:warning_message) { 'svgeez relies on SVGO 1.3.2. Continuing with standard sprite generation...' } + context "when SVGO executable is found" do + context "when SVGO version is not supported" do + let(:warning_message) { "svgeez relies on SVGO 1.3.2. Continuing with standard sprite generation..." } before do allow(optimizer).to receive(:supported?).and_return(false) end - it 'logs a warning' do - optimizer.optimize('') + it "logs a warning" do + optimizer.optimize("") expect(logger).to have_received(:warn).with(warning_message) end end - context 'when SVGO version is supported' do - let(:input_file_contents) { File.read('./spec/fixtures/icons/skull.svg') } + context "when SVGO version is supported" do + let(:input_file_contents) { File.read("./spec/fixtures/icons/skull.svg") } let(:output_file_contents) { %(\n) } - it 'returns a string' do + it "returns a string" do expect(optimizer.optimize(input_file_contents)).to eq(output_file_contents) end end diff --git a/spec/lib/svgeez/source_file_paths_spec.rb b/spec/lib/svgeez/source_file_paths_spec.rb index 3e5e9f6..5f87648 100644 --- a/spec/lib/svgeez/source_file_paths_spec.rb +++ b/spec/lib/svgeez/source_file_paths_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.describe Svgeez::Source, '#file_paths' do +RSpec.describe Svgeez::Source, "#file_paths" do let(:source) { described_class.new } let(:file_paths) do @@ -11,7 +11,7 @@ allow(Dir).to receive(:glob).and_return(file_paths) end - it 'returns an array of file paths' do + it "returns an array of file paths" do expect(source.file_paths).to eq(file_paths) end end diff --git a/spec/lib/svgeez/source_folder_path_spec.rb b/spec/lib/svgeez/source_folder_path_spec.rb index be815a0..e643685 100644 --- a/spec/lib/svgeez/source_folder_path_spec.rb +++ b/spec/lib/svgeez/source_folder_path_spec.rb @@ -1,23 +1,23 @@ # frozen_string_literal: true -RSpec.describe Svgeez::Source, '#folder_path' do - context 'when @source is not specified' do +RSpec.describe Svgeez::Source, "#folder_path" do + context "when @source is not specified" do let(:source) { described_class.new } - it 'returns the default folder path' do - expect(source.folder_path).to eq(File.expand_path('./_svgeez')) + it "returns the default folder path" do + expect(source.folder_path).to eq(File.expand_path("./_svgeez")) end end - context 'when @source is specified' do + context "when @source is specified" do let(:source) do described_class.new( - 'source' => './foo' + "source" => "./foo" ) end - it 'returns the specified folder path' do - expect(source.folder_path).to eq(File.expand_path('./foo')) + it "returns the specified folder path" do + expect(source.folder_path).to eq(File.expand_path("./foo")) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f4db14b..c621e4c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'simplecov' -require 'svgeez' +require "simplecov" +require "svgeez" RSpec.configure(&:disable_monkey_patching!) diff --git a/svgeez.gemspec b/svgeez.gemspec index 1e78362..5ddb03b 100644 --- a/svgeez.gemspec +++ b/svgeez.gemspec @@ -1,34 +1,34 @@ # frozen_string_literal: true -require_relative 'lib/svgeez/version' +require_relative "lib/svgeez/version" Gem::Specification.new do |spec| - spec.required_ruby_version = '>= 3.0' + spec.required_ruby_version = ">= 3.0" - spec.name = 'svgeez' + spec.name = "svgeez" spec.version = Svgeez::VERSION - spec.authors = ['Jason Garber'] - spec.email = ['jason@sixtwothree.org'] + spec.authors = ["Jason Garber"] + spec.email = ["jason@sixtwothree.org"] - spec.summary = 'Automatically generate an SVG sprite from a folder of SVG icons.' + spec.summary = "Automatically generate an SVG sprite from a folder of SVG icons." spec.description = spec.summary - spec.homepage = 'https://github.com/jgarber623/svgeez' - spec.license = 'MIT' + spec.homepage = "https://github.com/jgarber623/svgeez" + spec.license = "MIT" - spec.files = Dir['exe/**/*', 'lib/**/*'].reject { |f| File.directory?(f) } + spec.files = Dir["exe/**/*", "lib/**/*"].reject { |f| File.directory?(f) } spec.files += %w[LICENSE CHANGELOG.md README.md] spec.files += %w[svgeez.gemspec] - spec.bindir = 'exe' - spec.executables = ['svgeez'] - spec.require_paths = ['lib'] + spec.bindir = "exe" + spec.executables = ["svgeez"] + spec.require_paths = ["lib"] spec.metadata = { - 'bug_tracker_uri' => "#{spec.homepage}/issues", - 'changelog_uri' => "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md", - 'rubygems_mfa_required' => 'true' + "bug_tracker_uri" => "#{spec.homepage}/issues", + "changelog_uri" => "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md", + "rubygems_mfa_required" => "true" } - spec.add_runtime_dependency 'listen', '~> 3.5' - spec.add_runtime_dependency 'mercenary', '~> 0.4.0' + spec.add_runtime_dependency "listen", "~> 3.5" + spec.add_runtime_dependency "mercenary", "~> 0.4.0" end