Skip to content

Commit 4d6a693

Browse files
committed
Refactor specs
- Create `spec_helper` - Disable random spec order to allow spec to pass - Update RuboCop - Use `described_class` (autofix `RSpec/DescribedClass` offenses) - Remove unused variables to fix the following warnings: ``` spec/cached_asset_file_spec.rb:51: warning: assigned but unused variable - known_document_0 spec/transformation_pipeline/transformations/transformation_spec.rb:19: warning: assigned but unused variable - svg ``` - Add SimpleCov for code coverage
1 parent 2d8c66c commit 4d6a693

30 files changed

+249
-151
lines changed

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
*.rbc
33
.bundle
44
.config
5+
.ruby-*
56
.yardoc
6-
Gemfile.lock
7-
InstalledFiles
8-
_yardoc
97
coverage
108
doc/
9+
Gemfile.lock
10+
InstalledFiles
1111
lib/bundler/man
1212
pkg
1313
rdoc
14+
spec/examples.txt
1415
spec/reports
1516
test/tmp
1617
test/version_tmp
1718
tmp
18-
.ruby-*
19+
_yardoc

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--require spec_helper

.rubocop_todo.yml

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gemfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ gem "pry"
1010
gem "rake"
1111
gem "rspec"
1212

13-
gem "rubocop", "1.66.1"
14-
gem "rubocop-packaging", "0.5.2"
15-
gem "rubocop-performance", "1.22.1"
16-
gem "rubocop-rake", "0.6.0"
17-
gem "rubocop-rspec", "3.0.5"
13+
gem "rubocop", "1.69.0", require: false
14+
gem "rubocop-packaging", "0.5.2", require: false
15+
gem "rubocop-performance", "1.23.0", require: false
16+
gem "rubocop-rake", "0.6.0", require: false
17+
gem "rubocop-rspec", "3.2.0", require: false
18+
19+
gem "simplecov", require: false

spec/asset_file_spec.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
# frozen_string_literal: true
22

3-
require "inline_svg/finds_asset_paths"
4-
require "inline_svg/asset_file"
3+
require 'spec_helper'
54

6-
describe InlineSvg::AssetFile do
5+
RSpec.describe InlineSvg::AssetFile do
76
it "reads data from a file, after qualifying a full path" do
87
example_svg_path = File.expand_path(__FILE__, 'files/example.svg')
98
expect(InlineSvg::FindsAssetPaths).to receive(:by_filename).with('some filename').and_return example_svg_path
109

11-
expect(InlineSvg::AssetFile.named('some filename')).to include('This is a test')
10+
expect(described_class.named('some filename')).to include('This is a test')
1211
end
1312

1413
it "complains when the file cannot be read" do
1514
allow(InlineSvg::FindsAssetPaths).to receive(:by_filename).and_return('/this/path/does/not/exist')
1615

1716
expect do
18-
InlineSvg::AssetFile.named('some missing file')
17+
described_class.named('some missing file')
1918
end.to raise_error InlineSvg::AssetFile::FileNotFound
2019
end
2120

2221
it "complains when the file path was not found" do
2322
allow(InlineSvg::FindsAssetPaths).to receive(:by_filename).and_return(nil)
2423

2524
expect do
26-
InlineSvg::AssetFile.named('some missing file')
25+
described_class.named('some missing file')
2726
end.to raise_error InlineSvg::AssetFile::FileNotFound
2827
end
2928
end

spec/cached_asset_file_spec.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
# frozen_string_literal: true
22

3-
require 'pathname'
4-
require "inline_svg"
3+
require 'spec_helper'
54

6-
describe InlineSvg::CachedAssetFile do
5+
RSpec.describe InlineSvg::CachedAssetFile do
76
let(:fixture_path) { Pathname.new(File.expand_path('files/static_assets', __dir__)) }
87

98
it "loads assets under configured paths" do
109
known_document = File.read(fixture_path.join("assets0", "known-document.svg"))
1110

12-
asset_loader = InlineSvg::CachedAssetFile.new(paths: fixture_path.join("assets0"))
11+
asset_loader = described_class.new(paths: fixture_path.join("assets0"))
1312

1413
expect(asset_loader.named("known-document.svg")).to eq(known_document)
1514
end
1615

1716
it "does not include assets outside of configured paths" do
18-
asset_loader = InlineSvg::CachedAssetFile.new(paths: fixture_path.join("assets0"))
17+
asset_loader = described_class.new(paths: fixture_path.join("assets0"))
1918

2019
expect(fixture_path.join("assets1", "other-document.svg")).to be_file
2120
expect do
@@ -29,7 +28,7 @@
2928

3029
expect(known_document_0).not_to eq(known_document_1)
3130

32-
asset_loader = InlineSvg::CachedAssetFile.new(paths: fixture_path)
31+
asset_loader = described_class.new(paths: fixture_path)
3332

3433
expect(known_document_0).to eq(asset_loader.named("assets0/known-document.svg"))
3534
expect(known_document_1).to eq(asset_loader.named("assets1/known-document.svg"))
@@ -41,17 +40,16 @@
4140

4241
expect(known_document).not_to eq(known_document_2)
4342

44-
asset_loader = InlineSvg::CachedAssetFile.new(paths: fixture_path.join("assets0"), filters: /\.svg/)
43+
asset_loader = described_class.new(paths: fixture_path.join("assets0"), filters: /\.svg/)
4544

4645
expect(asset_loader.named("known-document")).to eq(known_document)
4746
expect(asset_loader.named("known-document-two")).to eq(known_document_2)
4847
end
4948

5049
it "filters wanted files by simple string matching" do
51-
known_document_0 = File.read(fixture_path.join("assets0", "known-document.svg"))
5250
known_document_1 = File.read(fixture_path.join("assets1", "known-document.svg"))
5351

54-
asset_loader = InlineSvg::CachedAssetFile.new(paths: fixture_path, filters: "assets1")
52+
asset_loader = described_class.new(paths: fixture_path, filters: "assets1")
5553

5654
expect do
5755
asset_loader.named("assets0/known-document.svg")
@@ -63,7 +61,7 @@
6361
it "filters wanted files by regex matching" do
6462
known_document_1 = File.read(fixture_path.join("assets1", "known-document.svg"))
6563

66-
asset_loader = InlineSvg::CachedAssetFile.new(paths: fixture_path, filters: ["assets1", /\.svg/])
64+
asset_loader = described_class.new(paths: fixture_path, filters: ["assets1", /\.svg/])
6765

6866
expect do
6967
asset_loader.named("assets1/some-file.txt")

spec/finds_asset_paths_spec.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# frozen_string_literal: true
22

3-
require 'pathname'
4-
require "inline_svg"
3+
require 'spec_helper'
54

6-
describe InlineSvg::FindsAssetPaths do
5+
RSpec.describe InlineSvg::FindsAssetPaths do
76
context "when sprockets finder returns an object which supports only the pathname method" do
87
it "returns fully qualified file paths from Sprockets" do
98
sprockets = double('SprocketsDouble')
@@ -15,7 +14,7 @@
1514
config.asset_finder = sprockets
1615
end
1716

18-
expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to eq Pathname('/full/path/to/some-file')
17+
expect(described_class.by_filename('some-file')).to eq Pathname('/full/path/to/some-file')
1918
end
2019
end
2120

@@ -30,7 +29,7 @@
3029
config.asset_finder = sprockets
3130
end
3231

33-
expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to eq Pathname('/full/path/to/some-file')
32+
expect(described_class.by_filename('some-file')).to eq Pathname('/full/path/to/some-file')
3433
end
3534
end
3635

@@ -44,7 +43,7 @@
4443
config.asset_finder = sprockets
4544
end
4645

47-
expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to be_nil
46+
expect(described_class.by_filename('some-file')).to be_nil
4847
end
4948
end
5049

@@ -59,7 +58,7 @@
5958
config.asset_finder = propshaft
6059
end
6160

62-
expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to eq Pathname('/full/path/to/some-file')
61+
expect(described_class.by_filename('some-file')).to eq Pathname('/full/path/to/some-file')
6362
end
6463
end
6564

@@ -74,7 +73,7 @@
7473
config.asset_finder = shakapacker
7574
end
7675

77-
expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to eq Pathname('/full/path/to/some-file')
76+
expect(described_class.by_filename('some-file')).to eq Pathname('/full/path/to/some-file')
7877
end
7978
end
8079

@@ -89,7 +88,7 @@
8988
config.asset_finder = shakapacker
9089
end
9190

92-
expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to eq Pathname('https://my-fancy-domain.test/full/path/to/some-file')
91+
expect(described_class.by_filename('some-file')).to eq Pathname('https://my-fancy-domain.test/full/path/to/some-file')
9392
end
9493
end
9594
end

spec/helpers/inline_svg_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require 'inline_svg'
3+
require 'spec_helper'
44

55
class WorkingCustomTransform < InlineSvg::CustomTransformation
66
def transform(doc)
@@ -11,7 +11,7 @@ def transform(doc)
1111
end
1212
end
1313

14-
describe InlineSvg::ActionView::Helpers do
14+
RSpec.describe InlineSvg::ActionView::Helpers do
1515
let(:helper) { (Class.new { include InlineSvg::ActionView::Helpers }).new }
1616

1717
shared_examples "inline_svg helper" do |helper_method:|

spec/id_generator_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# frozen_string_literal: true
22

3-
require "inline_svg/id_generator"
3+
require 'spec_helper'
44

5-
describe InlineSvg::IdGenerator do
5+
RSpec.describe InlineSvg::IdGenerator do
66
it "generates a hexencoded ID based on a salt and a random value" do
77
randomizer = -> { "some-random-value" }
88

9-
expect(InlineSvg::IdGenerator.generate("some-base", "some-salt", randomness: randomizer))
9+
expect(described_class.generate("some-base", "some-salt", randomness: randomizer))
1010
.to eq("at2c17mkqnvopy36iccxspura7wnreqf")
1111
end
1212
end

0 commit comments

Comments
 (0)