diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3bc6d7a..5f8202a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,17 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: leading, trailing -Layout/DotPosition: - Exclude: - - 'spec/finds_asset_paths_spec.rb' - - 'spec/helpers/inline_svg_spec.rb' - - 'spec/id_generator_spec.rb' - - 'spec/transformation_pipeline/transformations/aria_attributes_spec.rb' - - 'spec/transformation_pipeline/transformations/data_attributes_spec.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: IndentationWidth. # SupportedStyles: special_inside_parentheses, consistent, align_brackets @@ -41,22 +30,6 @@ Layout/MultilineMethodCallIndentation: - 'spec/transformation_pipeline/transformations/style_attribute_spec.rb' - 'spec/transformation_pipeline/transformations/view_box_spec.rb' -# This cop supports safe autocorrection (--autocorrect). -Lint/AmbiguousOperator: - Exclude: - - 'spec/io_resource_spec.rb' - -# This cop supports safe autocorrection (--autocorrect). -Lint/LiteralInInterpolation: - Exclude: - - 'spec/inline_svg_spec.rb' - -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowPercentLiteralArrayArgument. -Lint/RedundantSplatExpansion: - Exclude: - - 'lib/inline_svg.rb' - Lint/ShadowingOuterLocalVariable: Exclude: - 'lib/inline_svg/transform_pipeline/transformations/description.rb' @@ -102,17 +75,6 @@ Performance/MapCompact: Exclude: - 'lib/inline_svg/transform_pipeline/transformations.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AutoCorrect. -RSpec/BeEmpty: - Exclude: - - 'spec/transformation_pipeline/transformations_spec.rb' - -# This cop supports safe autocorrection (--autocorrect). -RSpec/ContextMethod: - Exclude: - - 'spec/transformation_pipeline/transformations/transformation_spec.rb' - # Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without RSpec/ContextWording: @@ -121,7 +83,6 @@ RSpec/ContextWording: - 'spec/inline_svg_spec.rb' - 'spec/io_resource_spec.rb' - 'spec/transformation_pipeline/transformations/aria_attributes_spec.rb' - - 'spec/transformation_pipeline/transformations/transformation_spec.rb' - 'spec/transformation_pipeline/transformations_spec.rb' # This cop supports unsafe autocorrection (--autocorrect-all). @@ -140,12 +101,6 @@ RSpec/EmptyExampleGroup: RSpec/ExampleLength: Max: 32 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: . -# SupportedStyles: implicit, each, example -RSpec/HookArgument: - EnforcedStyle: each - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit @@ -153,11 +108,6 @@ RSpec/ImplicitSubject: Exclude: - 'spec/io_resource_spec.rb' -# This cop supports safe autocorrection (--autocorrect). -RSpec/MatchArray: - Exclude: - - 'spec/transformation_pipeline/transformations_spec.rb' - # Configuration parameters: . # SupportedStyles: have_received, receive RSpec/MessageSpies: @@ -176,14 +126,6 @@ RSpec/NamedSubject: RSpec/NestedGroups: Max: 4 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: not_to, to_not -RSpec/NotToNot: - Exclude: - - 'spec/helpers/inline_svg_spec.rb' - - 'spec/io_resource_spec.rb' - RSpec/RepeatedExampleGroupDescription: Exclude: - 'spec/helpers/inline_svg_spec.rb' @@ -254,18 +196,6 @@ Style/CollectionCompact: Style/Documentation: Enabled: false -# This cop supports safe autocorrection (--autocorrect). -Style/EachWithObject: - Exclude: - - 'lib/inline_svg/transform_pipeline/transformations.rb' - -# This cop supports safe autocorrection (--autocorrect). -Style/ExpandPathArguments: - Exclude: - - 'spec/cached_asset_file_spec.rb' - - 'spec/helpers/inline_svg_spec.rb' - - 'spec/io_resource_spec.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never @@ -277,15 +207,6 @@ Style/FrozenStringLiteralComment: Style/GuardClause: Exclude: - 'lib/inline_svg.rb' - - 'lib/inline_svg/action_view/helpers.rb' - -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. -# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys -# SupportedShorthandSyntax: always, never, either, consistent, either_consistent -Style/HashSyntax: - Exclude: - - 'Rakefile' # This cop supports safe autocorrection (--autocorrect). Style/IfUnlessModifier: @@ -294,12 +215,6 @@ Style/IfUnlessModifier: - 'lib/inline_svg/static_asset_finder.rb' - 'lib/inline_svg/transform_pipeline/transformations/aria_attributes.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: InverseMethods, InverseBlocks. -Style/InverseMethods: - Exclude: - - 'lib/inline_svg/transform_pipeline/transformations.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). Style/MapIntoArray: Exclude: @@ -313,19 +228,6 @@ Style/MutableConstant: - 'lib/inline_svg/asset_file.rb' - 'lib/inline_svg/version.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowedMethods. -# AllowedMethods: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with -Style/NestedParenthesizedCalls: - Exclude: - - 'spec/io_resource_spec.rb' - -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: IncludeSemanticChanges. -Style/NonNilCheck: - Exclude: - - 'lib/inline_svg/transform_pipeline/transformations.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle, AllowedCompactTypes. # SupportedStyles: compact, exploded @@ -341,24 +243,6 @@ Style/RedundantArgument: Exclude: - 'lib/inline_svg/transform_pipeline/transformations/class_attribute.rb' -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantBegin: - Exclude: - - 'lib/inline_svg.rb' - -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantConstantBase: - Exclude: - - 'spec/propshaft_asset_finder_spec.rb' - - 'spec/static_asset_finder_spec.rb' - - 'spec/webpack_asset_finder_spec.rb' - -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'lib/inline_svg/action_view/helpers.rb' - # This cop supports safe autocorrection (--autocorrect). Style/RedundantSelf: Exclude: @@ -372,13 +256,6 @@ Style/RedundantSelf: - 'lib/inline_svg/transform_pipeline/transformations/transformation.rb' - 'lib/inline_svg/transform_pipeline/transformations/width.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, AllowInnerSlashes. -# SupportedStyles: slashes, percent_r, mixed -Style/RegexpLiteral: - Exclude: - - 'spec/transformation_pipeline/transformations/transformation_spec.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. # AllowedMethods: present?, blank?, presence, try, try! diff --git a/Rakefile b/Rakefile index 88c85cf..0391f03 100644 --- a/Rakefile +++ b/Rakefile @@ -5,4 +5,4 @@ RSpec::Core::RakeTask.new(:spec) do |t| t.pattern = Dir.glob("spec/**/*_spec.rb") # t.rspec_opts = "--format documentation" end -task :default => :spec +task default: :spec diff --git a/lib/inline_svg.rb b/lib/inline_svg.rb index 7a76776..8ad5d44 100644 --- a/lib/inline_svg.rb +++ b/lib/inline_svg.rb @@ -30,16 +30,14 @@ def initialize end def asset_file=(custom_asset_file) - begin - method = custom_asset_file.method(:named) - if method.arity == 1 - @asset_file = custom_asset_file - else - raise InlineSvg::Configuration::Invalid.new("asset_file should implement the #named method with arity 1") - end - rescue NameError - raise InlineSvg::Configuration::Invalid.new("asset_file should implement the #named method") + method = custom_asset_file.method(:named) + if method.arity == 1 + @asset_file = custom_asset_file + else + raise InlineSvg::Configuration::Invalid.new("asset_file should implement the #named method with arity 1") end + rescue NameError + raise InlineSvg::Configuration::Invalid.new("asset_file should implement the #named method") end def asset_finder=(finder) @@ -67,7 +65,7 @@ def add_custom_transformation(options) raise InlineSvg::Configuration::Invalid.new("#{options.fetch(:transform)} should implement the .create_with_value and #transform methods") end - @custom_transformations.merge!(Hash[*[options.fetch(:attribute, :no_attribute), options]]) + @custom_transformations.merge!(options.fetch(:attribute, :no_attribute) => options) end def raise_on_file_not_found=(value) diff --git a/lib/inline_svg/action_view/helpers.rb b/lib/inline_svg/action_view/helpers.rb index 957b6b0..8d945fe 100644 --- a/lib/inline_svg/action_view/helpers.rb +++ b/lib/inline_svg/action_view/helpers.rb @@ -54,9 +54,9 @@ def placeholder(filename) not_found_message = "'#{ERB::Util.html_escape_once(filename)}' #{extension_hint(filename)}" if css_class.nil? - return "".html_safe + "".html_safe else - return "".html_safe + "".html_safe end end diff --git a/lib/inline_svg/transform_pipeline/transformations.rb b/lib/inline_svg/transform_pipeline/transformations.rb index 39558f7..0759e85 100644 --- a/lib/inline_svg/transform_pipeline/transformations.rb +++ b/lib/inline_svg/transform_pipeline/transformations.rb @@ -24,11 +24,10 @@ def self.custom_transformations end def self.magnify_priorities(transforms) - transforms.inject({}) do |output, (name, definition)| + transforms.each_with_object({}) do |(name, definition), output| priority = definition.fetch(:priority, built_in_transformations.size) output[name] = definition.merge({ priority: magnify(priority) }) - output end end @@ -65,7 +64,7 @@ def self.without_empty_values(params) def self.all_default_values custom_transformations .values - .select { |opt| opt[:default_value] != nil } + .reject { |opt| opt[:default_value].nil? } .map { |opt| [opt[:attribute], opt[:default_value]] } .inject({}) { |options, attrs| options.merge!(attrs[0] => attrs[1]) } end diff --git a/spec/cached_asset_file_spec.rb b/spec/cached_asset_file_spec.rb index e99dbe2..29c0284 100644 --- a/spec/cached_asset_file_spec.rb +++ b/spec/cached_asset_file_spec.rb @@ -4,7 +4,7 @@ require "inline_svg" describe InlineSvg::CachedAssetFile do - let(:fixture_path) { Pathname.new(File.expand_path("../files/static_assets", __FILE__)) } + let(:fixture_path) { Pathname.new(File.expand_path('files/static_assets', __dir__)) } it "loads assets under configured paths" do known_document = File.read(fixture_path.join("assets0", "known-document.svg")) diff --git a/spec/finds_asset_paths_spec.rb b/spec/finds_asset_paths_spec.rb index 4354490..b68cefd 100644 --- a/spec/finds_asset_paths_spec.rb +++ b/spec/finds_asset_paths_spec.rb @@ -6,8 +6,8 @@ it "returns fully qualified file paths from Sprockets" do sprockets = double('SprocketsDouble') - expect(sprockets).to receive(:find_asset).with('some-file'). - and_return(double(pathname: Pathname('/full/path/to/some-file'))) + expect(sprockets).to receive(:find_asset).with('some-file') + .and_return(double(pathname: Pathname('/full/path/to/some-file'))) InlineSvg.configure do |config| config.asset_finder = sprockets @@ -21,8 +21,8 @@ it "returns fully qualified file paths from Sprockets" do sprockets = double('SprocketsDouble') - expect(sprockets).to receive(:find_asset).with('some-file'). - and_return(double(filename: Pathname('/full/path/to/some-file'))) + expect(sprockets).to receive(:find_asset).with('some-file') + .and_return(double(filename: Pathname('/full/path/to/some-file'))) InlineSvg.configure do |config| config.asset_finder = sprockets @@ -50,8 +50,8 @@ it "returns fully qualified file paths from Propshaft" do propshaft = double('PropshaftDouble') - expect(propshaft).to receive(:find_asset).with('some-file'). - and_return(double(pathname: Pathname('/full/path/to/some-file'))) + expect(propshaft).to receive(:find_asset).with('some-file') + .and_return(double(pathname: Pathname('/full/path/to/some-file'))) InlineSvg.configure do |config| config.asset_finder = propshaft @@ -65,8 +65,8 @@ it "returns the fully qualified file path" do shakapacker = double('ShakapackerDouble') - expect(shakapacker).to receive(:find_asset).with('some-file'). - and_return(double(filename: Pathname('/full/path/to/some-file'))) + expect(shakapacker).to receive(:find_asset).with('some-file') + .and_return(double(filename: Pathname('/full/path/to/some-file'))) InlineSvg.configure do |config| config.asset_finder = shakapacker @@ -80,8 +80,8 @@ it "returns the fully qualified file path" do shakapacker = double('ShakapackerDouble') - expect(shakapacker).to receive(:find_asset).with('some-file'). - and_return(double(filename: Pathname('https://my-fancy-domain.test/full/path/to/some-file'))) + expect(shakapacker).to receive(:find_asset).with('some-file') + .and_return(double(filename: Pathname('https://my-fancy-domain.test/full/path/to/some-file'))) InlineSvg.configure do |config| config.asset_finder = shakapacker diff --git a/spec/helpers/inline_svg_spec.rb b/spec/helpers/inline_svg_spec.rb index 1626bf7..f67945d 100644 --- a/spec/helpers/inline_svg_spec.rb +++ b/spec/helpers/inline_svg_spec.rb @@ -14,7 +14,7 @@ def transform(doc) shared_examples "inline_svg helper" do |helper_method:| context "when passed the name of an SVG that does not exist" do - after(:each) do + after do InlineSvg.reset_configuration! end @@ -24,9 +24,9 @@ def transform(doc) config.raise_on_file_not_found = true end - allow(InlineSvg::AssetFile).to receive(:named). - with('some-missing-file.svg'). - and_raise(InlineSvg::AssetFile::FileNotFound.new) + allow(InlineSvg::AssetFile).to receive(:named) + .with('some-missing-file.svg') + .and_raise(InlineSvg::AssetFile::FileNotFound.new) expect { helper.send(helper_method, 'some-missing-file.svg') @@ -35,9 +35,9 @@ def transform(doc) end it "returns an empty, html safe, SVG document as a placeholder" do - allow(InlineSvg::AssetFile).to receive(:named). - with('some-missing-file.svg'). - and_raise(InlineSvg::AssetFile::FileNotFound.new) + allow(InlineSvg::AssetFile).to receive(:named) + .with('some-missing-file.svg') + .and_raise(InlineSvg::AssetFile::FileNotFound.new) output = helper.send(helper_method, 'some-missing-file.svg') expect(output).to eq "" @@ -46,9 +46,9 @@ def transform(doc) it "escapes malicious input" do malicious = "-->.svg" - allow(InlineSvg::AssetFile).to receive(:named). - with(malicious). - and_raise(InlineSvg::AssetFile::FileNotFound.new) + allow(InlineSvg::AssetFile).to receive(:named) + .with(malicious) + .and_raise(InlineSvg::AssetFile::FileNotFound.new) output = helper.send(helper_method, malicious) expect(output).to eq "" @@ -56,9 +56,9 @@ def transform(doc) end it "gives a helpful hint when no .svg extension is provided in the filename" do - allow(InlineSvg::AssetFile).to receive(:named). - with('missing-file-with-no-extension'). - and_raise(InlineSvg::AssetFile::FileNotFound.new) + allow(InlineSvg::AssetFile).to receive(:named) + .with('missing-file-with-no-extension') + .and_raise(InlineSvg::AssetFile::FileNotFound.new) output = helper.send(helper_method, 'missing-file-with-no-extension') expect(output).to eq "" @@ -69,9 +69,9 @@ def transform(doc) config.svg_not_found_css_class = 'missing-svg' end - allow(InlineSvg::AssetFile).to receive(:named). - with('some-other-missing-file.svg'). - and_raise(InlineSvg::AssetFile::FileNotFound.new) + allow(InlineSvg::AssetFile).to receive(:named) + .with('some-other-missing-file.svg') + .and_raise(InlineSvg::AssetFile::FileNotFound.new) output = helper.send(helper_method, 'some-other-missing-file.svg') expect(output).to eq "" @@ -80,9 +80,9 @@ def transform(doc) context "and a fallback that does exist" do it "displays the fallback" do - allow(InlineSvg::AssetFile).to receive(:named). - with('missing.svg'). - and_raise(InlineSvg::AssetFile::FileNotFound.new) + allow(InlineSvg::AssetFile).to receive(:named) + .with('missing.svg') + .and_raise(InlineSvg::AssetFile::FileNotFound.new) fallback_file = '' allow(InlineSvg::AssetFile).to receive(:named).with('fallback.svg').and_return(fallback_file) @@ -146,13 +146,13 @@ def transform(doc) end context "with custom transformations" do - before(:each) do + before do InlineSvg.configure do |config| config.add_custom_transformation({ attribute: :custom, transform: WorkingCustomTransform }) end end - after(:each) do + after do InlineSvg.reset_configuration! end @@ -165,13 +165,13 @@ def transform(doc) end context "with custom transformations using a default value" do - before(:each) do + before do InlineSvg.configure do |config| config.add_custom_transformation({ attribute: :custom, transform: WorkingCustomTransform, default_value: 'default value' }) end end - after(:each) do + after do InlineSvg.reset_configuration! end @@ -203,13 +203,13 @@ def transform(doc) it 'accept IO' do expect(InlineSvg::IOResource).to receive(:===).with(argument).and_return(true) expect(InlineSvg::IOResource).to receive(:read).with(argument) - expect(InlineSvg::AssetFile).to_not receive(:named) + expect(InlineSvg::AssetFile).not_to receive(:named) helper.send(helper_method, argument) end it 'accept filename' do expect(InlineSvg::IOResource).to receive(:===).with(argument).and_return(false) - expect(InlineSvg::IOResource).to_not receive(:read) + expect(InlineSvg::IOResource).not_to receive(:read) expect(InlineSvg::AssetFile).to receive(:named).with(argument) helper.send(helper_method, argument) end @@ -217,7 +217,7 @@ def transform(doc) context 'when passed IO object argument' do let(:io_object) { double('io_object') } - let(:file_path) { File.expand_path('../../files/example.svg', __FILE__) } + let(:file_path) { File.expand_path('../files/example.svg', __dir__) } let(:answer) { File.read(file_path) } it 'return valid svg' do diff --git a/spec/id_generator_spec.rb b/spec/id_generator_spec.rb index f69f085..6543824 100644 --- a/spec/id_generator_spec.rb +++ b/spec/id_generator_spec.rb @@ -4,7 +4,7 @@ it "generates a hexencoded ID based on a salt and a random value" do randomizer = -> { "some-random-value" } - expect(InlineSvg::IdGenerator.generate("some-base", "some-salt", randomness: randomizer)). - to eq("at2c17mkqnvopy36iccxspura7wnreqf") + expect(InlineSvg::IdGenerator.generate("some-base", "some-salt", randomness: randomizer)) + .to eq("at2c17mkqnvopy36iccxspura7wnreqf") end end diff --git a/spec/inline_svg_spec.rb b/spec/inline_svg_spec.rb index 6821be6..63a7c79 100644 --- a/spec/inline_svg_spec.rb +++ b/spec/inline_svg_spec.rb @@ -120,7 +120,7 @@ def self.named(filename); end InlineSvg.configure do |config| config.add_custom_transformation(attribute: :irrelevant, transform: :not_a_class) end - end.to raise_error(InlineSvg::Configuration::Invalid, /#{:not_a_class} should implement the .create_with_value and #transform methods/) + end.to raise_error(InlineSvg::Configuration::Invalid, /not_a_class should implement the .create_with_value and #transform methods/) end end end diff --git a/spec/io_resource_spec.rb b/spec/io_resource_spec.rb index d0be2e5..2825981 100644 --- a/spec/io_resource_spec.rb +++ b/spec/io_resource_spec.rb @@ -42,12 +42,12 @@ it "empty" do rio.read - expect(subject.read rio).to eq '' + expect(subject.read(rio)).to eq '' end it "twice" do - expect(subject.read rio).to eq answer - expect(subject.read rio).to eq answer + expect(subject.read(rio)).to eq answer + expect(subject.read(rio)).to eq answer end it "write only raise error" do @@ -62,18 +62,18 @@ let(:rio) { StringIO.new(answer, 'r') } let(:wio) { StringIO.new('write', 'w') } - instance_exec &tests + instance_exec(&tests) end context 'File object' do - let(:file_path) { File.expand_path('../files/example.svg', __FILE__) } + let(:file_path) { File.expand_path('files/example.svg', __dir__) } let(:answer) { File.read(file_path) } let(:rio) { File.new(file_path, 'r') } let(:wio) { File.new('/dev/null', 'w') } - instance_exec &tests + instance_exec(&tests) it 'has non empty body' do - expect(answer).to_not eq '' + expect(answer).not_to eq '' end end end diff --git a/spec/propshaft_asset_finder_spec.rb b/spec/propshaft_asset_finder_spec.rb index 81c46c0..6d8c2bc 100644 --- a/spec/propshaft_asset_finder_spec.rb +++ b/spec/propshaft_asset_finder_spec.rb @@ -4,7 +4,7 @@ context "when the file is not found" do it "returns nil" do stub_const('Rails', double('Rails').as_null_object) - expect(::Rails.application.assets.load_path).to receive(:find).with('some-file').and_return(nil) + expect(Rails.application.assets.load_path).to receive(:find).with('some-file').and_return(nil) expect(InlineSvg::PropshaftAssetFinder.find_asset('some-file').pathname).to be_nil end @@ -15,7 +15,7 @@ stub_const('Rails', double('Rails').as_null_object) asset = double('Asset') expect(asset).to receive(:path).and_return(Pathname.new('/full/path/to/some-file')) - expect(::Rails.application.assets.load_path).to receive(:find).with('some-file').and_return(asset) + expect(Rails.application.assets.load_path).to receive(:find).with('some-file').and_return(asset) expect(InlineSvg::PropshaftAssetFinder.find_asset('some-file').pathname).to eq Pathname('/full/path/to/some-file') end diff --git a/spec/static_asset_finder_spec.rb b/spec/static_asset_finder_spec.rb index 4bb14be..e4c16e5 100644 --- a/spec/static_asset_finder_spec.rb +++ b/spec/static_asset_finder_spec.rb @@ -4,7 +4,7 @@ context "when the file is not found" do it "returns nil" do stub_const('Rails', double('Rails').as_null_object) - expect(::Rails.application.config.assets).to receive(:compile).and_return(true) + expect(Rails.application.config.assets).to receive(:compile).and_return(true) expect(described_class.find_asset('some-file').pathname).to be_nil end @@ -13,11 +13,11 @@ context "when the file is found" do it "returns fully qualified file path from Sprockets" do stub_const('Rails', double('Rails').as_null_object) - expect(::Rails.application.config.assets).to receive(:compile).and_return(true) + expect(Rails.application.config.assets).to receive(:compile).and_return(true) pathname = Pathname.new('/full/path/to/some-file') asset = double('Asset') expect(asset).to receive(:filename).and_return(pathname) - expect(::Rails.application.assets).to receive(:[]).with('some-file').and_return(asset) + expect(Rails.application.assets).to receive(:[]).with('some-file').and_return(asset) expect(described_class.find_asset('some-file').pathname).to eq(pathname) end diff --git a/spec/transformation_pipeline/transformations/aria_attributes_spec.rb b/spec/transformation_pipeline/transformations/aria_attributes_spec.rb index 65a452a..003eb26 100644 --- a/spec/transformation_pipeline/transformations/aria_attributes_spec.rb +++ b/spec/transformation_pipeline/transformations/aria_attributes_spec.rb @@ -15,8 +15,8 @@ document = Nokogiri::XML::Document.parse("Some titleSome document") transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value(true) - expect(InlineSvg::IdGenerator).to receive(:generate).with("title", "Some title"). - and_return("some-id") + expect(InlineSvg::IdGenerator).to receive(:generate).with("title", "Some title") + .and_return("some-id") expect(transformation.transform(document).to_html).to eq( "Some titleSome document\n" @@ -27,8 +27,8 @@ document = Nokogiri::XML::Document.parse("Some descriptionSome document") transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value(true) - expect(InlineSvg::IdGenerator).to receive(:generate).with("desc", "Some description"). - and_return("some-id") + expect(InlineSvg::IdGenerator).to receive(:generate).with("desc", "Some description") + .and_return("some-id") expect(transformation.transform(document).to_html).to eq( "Some descriptionSome document\n" @@ -39,10 +39,10 @@ document = Nokogiri::XML::Document.parse("Some titleSome descriptionSome document") transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value(true) - expect(InlineSvg::IdGenerator).to receive(:generate).with("title", "Some title"). - and_return("some-id") - expect(InlineSvg::IdGenerator).to receive(:generate).with("desc", "Some description"). - and_return("some-other-id") + expect(InlineSvg::IdGenerator).to receive(:generate).with("title", "Some title") + .and_return("some-id") + expect(InlineSvg::IdGenerator).to receive(:generate).with("desc", "Some description") + .and_return("some-other-id") expect(transformation.transform(document).to_html).to eq( "Some title\nSome descriptionSome document\n" @@ -53,10 +53,10 @@ document = Nokogiri::XML::Document.parse("Some titleSome descriptionSome document") transformation = InlineSvg::TransformPipeline::Transformations::AriaAttributes.create_with_value(true) - expect(InlineSvg::IdGenerator).to receive(:generate).with("my-title", "Some title"). - and_return("some-id") - expect(InlineSvg::IdGenerator).to receive(:generate).with("my-desc", "Some description"). - and_return("some-other-id") + expect(InlineSvg::IdGenerator).to receive(:generate).with("my-title", "Some title") + .and_return("some-id") + expect(InlineSvg::IdGenerator).to receive(:generate).with("my-desc", "Some description") + .and_return("some-other-id") expect(transformation.transform(document).to_html).to eq( "Some title\nSome descriptionSome document\n" diff --git a/spec/transformation_pipeline/transformations/data_attributes_spec.rb b/spec/transformation_pipeline/transformations/data_attributes_spec.rb index 89f5fd5..09f0f82 100644 --- a/spec/transformation_pipeline/transformations/data_attributes_spec.rb +++ b/spec/transformation_pipeline/transformations/data_attributes_spec.rb @@ -31,8 +31,8 @@ context "when multiple data attributes are supplied" do it "adds data attributes to the SVG for each supplied value" do document = Nokogiri::XML::Document.parse('Some document') - transformation = InlineSvg::TransformPipeline::Transformations::DataAttributes. - create_with_value({ some: "value", other: "thing" }) + transformation = InlineSvg::TransformPipeline::Transformations::DataAttributes + .create_with_value({ some: "value", other: "thing" }) expect(transformation.transform(document).to_html).to eq( "Some document\n" @@ -43,8 +43,8 @@ context "when a non-hash is supplied" do it "does not update the SVG document" do document = Nokogiri::XML::Document.parse('Some document') - transformation = InlineSvg::TransformPipeline::Transformations::DataAttributes. - create_with_value("some non-hash") + transformation = InlineSvg::TransformPipeline::Transformations::DataAttributes + .create_with_value("some non-hash") expect(transformation.transform(document).to_html).to eq( "Some document\n" diff --git a/spec/transformation_pipeline/transformations/transformation_spec.rb b/spec/transformation_pipeline/transformations/transformation_spec.rb index 1dcc364..3e4580f 100644 --- a/spec/transformation_pipeline/transformations/transformation_spec.rb +++ b/spec/transformation_pipeline/transformations/transformation_spec.rb @@ -2,7 +2,7 @@ require 'inline_svg/transform_pipeline' describe InlineSvg::TransformPipeline::Transformations::Transformation do - context "#with_svg" do + describe "#with_svg" do it "returns a Nokogiri::XML::Document representing the parsed document fragment" do document = Nokogiri::XML::Document.parse("Some document") @@ -23,7 +23,7 @@ returned_document = transformation.with_svg(document, &b) end.to yield_control - expect(returned_document.to_s).to match(/Some document<\/svg>/) + expect(returned_document.to_s).to match(%r{Some document}) end it "does not yield if the document does not contain an SVG element at the root" do diff --git a/spec/transformation_pipeline/transformations_spec.rb b/spec/transformation_pipeline/transformations_spec.rb index 038bd46..a64ef09 100644 --- a/spec/transformation_pipeline/transformations_spec.rb +++ b/spec/transformation_pipeline/transformations_spec.rb @@ -29,7 +29,7 @@ class ASecondCustomTransform < ACustomTransform; end aria_hidden: "true" ) - expect(transformations.map(&:class)).to match_array([ + expect(transformations.map(&:class)).to contain_exactly( InlineSvg::TransformPipeline::Transformations::NoComment, InlineSvg::TransformPipeline::Transformations::ClassAttribute, InlineSvg::TransformPipeline::Transformations::StyleAttribute, @@ -44,7 +44,7 @@ class ASecondCustomTransform < ACustomTransform; end InlineSvg::TransformPipeline::Transformations::PreserveAspectRatio, InlineSvg::TransformPipeline::Transformations::AriaAttributes, InlineSvg::TransformPipeline::Transformations::AriaHiddenAttribute - ]) + ) end it "returns transformations in priority order" do @@ -78,7 +78,7 @@ class ASecondCustomTransform < ACustomTransform; end not_a_real_transform: 'irrelevant' ) - expect(transformations.map(&:class)).to match_array([]) + expect(transformations.map(&:class)).to be_empty end it "does not return a transformation when a value is not supplied" do @@ -86,19 +86,19 @@ class ASecondCustomTransform < ACustomTransform; end title: nil ) - expect(transformations.map(&:class)).to match_array([]) + expect(transformations.map(&:class)).to be_empty end end context "custom transformations" do - before(:each) do + before do InlineSvg.configure do |config| config.add_custom_transformation({ transform: ACustomTransform, attribute: :my_transform, priority: 2 }) config.add_custom_transformation({ transform: ASecondCustomTransform, attribute: :my_other_transform, priority: 1 }) end end - after(:each) do + after do InlineSvg.reset_configuration! end @@ -107,7 +107,7 @@ class ASecondCustomTransform < ACustomTransform; end my_transform: :irrelevant ) - expect(transformations.map(&:class)).to match_array([ACustomTransform]) + expect(transformations.map(&:class)).to contain_exactly(ACustomTransform) end it "returns configured custom transformations in priority order" do diff --git a/spec/webpack_asset_finder_spec.rb b/spec/webpack_asset_finder_spec.rb index eb94ee7..d0a1b61 100644 --- a/spec/webpack_asset_finder_spec.rb +++ b/spec/webpack_asset_finder_spec.rb @@ -5,7 +5,7 @@ it "returns nil" do stub_const('Rails', double('Rails').as_null_object) stub_const('Shakapacker', double('Shakapacker').as_null_object) - expect(::Shakapacker.manifest).to receive(:lookup).with('some-file').and_return(nil) + expect(Shakapacker.manifest).to receive(:lookup).with('some-file').and_return(nil) expect(described_class.find_asset('some-file').pathname).to be_nil end