Skip to content

Commit

Permalink
Add test case to ensure viewBox attribute on root element of SVG
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed May 19, 2021
1 parent 703cfab commit 5a07614
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions spec/svg_spec.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
require 'rails_helper'

RSpec.describe 'SVG files' do
Dir[Rails.root.join('**', '*.svg')].reject { |f| f.include?('node_modules') }.each do |svg_path|
relative_path = svg_path.sub(Rails.root.to_s, '')

next if %w[vendor node_modules].include?(relative_path.split('/')[1])

files = Dir.glob('{app,public}/**/*.svg', base: Rails.root)
files.reject! { |f| f.start_with? 'public/assets/' }
files.each do |relative_path|
describe relative_path do
it 'does not contain inline style tags (that render poorly in IE due to CSP)' do
doc = Nokogiri::XML(File.read(svg_path))
let(:subject) { Nokogiri::XML(File.read(Rails.root.join(relative_path))) }

expect(doc.css('style')).to be_empty.or(
it 'does not contain inline style tags (that render poorly in IE due to CSP)' do
expect(subject.css('style')).to be_empty.or(
have_attributes(text: match(%r{^\s*/\*\!lint-ignore\*/})),
)
end

it 'defines viewBox attribute on root svg tag' do
expect(subject.css(':root[viewBox]')).to be_present
end
end
end
end

0 comments on commit 5a07614

Please sign in to comment.