Skip to content

Commit 7a05360

Browse files
committed
Refactor specs
- Create `spec_helper` and `.rspec` - Add `spec/examples.txt` to `.gitignore` and sort alphabetically. `spec/examples.txt` allows to run specs with `--only-failures` option - Add SimpleCov for code coverage. Run specs with `COVERAGE` env variable set to any value
1 parent 3a12c9e commit 7a05360

29 files changed

+141
-36
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

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ gem "rubocop-packaging", "0.5.2", require: false
1515
gem "rubocop-performance", "1.23.0", require: false
1616
gem "rubocop-rake", "0.6.0", require: false
1717
gem "rubocop-rspec", "3.3.0", require: false
18+
19+
gem "simplecov", require: false

spec/asset_file_spec.rb

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

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

65
RSpec.describe InlineSvg::AssetFile do
76
it "reads data from a file, after qualifying a full path" do

spec/cached_asset_file_spec.rb

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

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

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

spec/finds_asset_paths_spec.rb

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

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

65
RSpec.describe InlineSvg::FindsAssetPaths do
76
after do

spec/helpers/inline_svg_spec.rb

Lines changed: 1 addition & 1 deletion
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)

spec/id_generator_spec.rb

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

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

55
RSpec.describe InlineSvg::IdGenerator do
66
it "generates a hexencoded ID based on a salt and a random value" do

spec/inline_svg_spec.rb

Lines changed: 1 addition & 1 deletion
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 MyCustomTransform
66
def self.create_with_value(value); end

spec/io_resource_spec.rb

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

3-
require "inline_svg"
4-
require "stringio"
5-
require "tempfile"
3+
require 'tempfile'
4+
5+
require 'spec_helper'
66

77
RSpec.describe InlineSvg::IOResource do
88
it "support api methods" do

spec/propshaft_asset_finder_spec.rb

Lines changed: 1 addition & 1 deletion
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
RSpec.describe InlineSvg::PropshaftAssetFinder do
66
context "when the file is not found" do

spec/spec_helper.rb

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# frozen_string_literal: true
2+
3+
if ENV.fetch('COVERAGE', false)
4+
require 'simplecov'
5+
6+
SimpleCov.start do
7+
add_filter %r{^/spec/}
8+
end
9+
end
10+
11+
require 'inline_svg'
12+
13+
# This file was generated by the `rspec --init` command. Conventionally, all
14+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
15+
# The generated `.rspec` file contains `--require spec_helper` which will cause
16+
# this file to always be loaded, without a need to explicitly require it in any
17+
# files.
18+
#
19+
# Given that it is always loaded, you are encouraged to keep this file as
20+
# light-weight as possible. Requiring heavyweight dependencies from this file
21+
# will add to the boot time of your test suite on EVERY test run, even for an
22+
# individual file that may not need all of that loaded. Instead, consider making
23+
# a separate helper file that requires the additional dependencies and performs
24+
# the additional setup, and require it from the spec files that actually need
25+
# it.
26+
#
27+
# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
28+
RSpec.configure do |config|
29+
# rspec-expectations config goes here. You can use an alternate
30+
# assertion/expectation library such as wrong or the stdlib/minitest
31+
# assertions if you prefer.
32+
config.expect_with :rspec do |expectations|
33+
# This option will default to `true` in RSpec 4. It makes the `description`
34+
# and `failure_message` of custom matchers include text for helper methods
35+
# defined using `chain`, e.g.:
36+
# be_bigger_than(2).and_smaller_than(4).description
37+
# # => "be bigger than 2 and smaller than 4"
38+
# ...rather than:
39+
# # => "be bigger than 2"
40+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
41+
end
42+
43+
# rspec-mocks config goes here. You can use an alternate test double
44+
# library (such as bogus or mocha) by changing the `mock_with` option here.
45+
config.mock_with :rspec do |mocks|
46+
# Prevents you from mocking or stubbing a method that does not exist on
47+
# a real object. This is generally recommended, and will default to
48+
# `true` in RSpec 4.
49+
mocks.verify_partial_doubles = true
50+
end
51+
52+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
53+
# have no way to turn it off -- the option exists only for backwards
54+
# compatibility in RSpec 3). It causes shared context metadata to be
55+
# inherited by the metadata hash of host groups and examples, rather than
56+
# triggering implicit auto-inclusion in groups with matching metadata.
57+
config.shared_context_metadata_behavior = :apply_to_host_groups
58+
59+
# This allows you to limit a spec run to individual examples or groups
60+
# you care about by tagging them with `:focus` metadata. When nothing
61+
# is tagged with `:focus`, all examples get run. RSpec also provides
62+
# aliases for `it`, `describe`, and `context` that include `:focus`
63+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
64+
config.filter_run_when_matching :focus
65+
66+
# Allows RSpec to persist some state between runs in order to support
67+
# the `--only-failures` and `--next-failure` CLI options. We recommend
68+
# you configure your source control system to ignore this file.
69+
config.example_status_persistence_file_path = "spec/examples.txt"
70+
71+
# Limits the available syntax to the non-monkey patched syntax that is
72+
# recommended. For more details, see:
73+
# https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
74+
config.disable_monkey_patching!
75+
76+
# This setting enables warnings. It's recommended, but in some cases may
77+
# be too noisy due to issues in dependencies.
78+
config.warnings = true
79+
80+
# Many RSpec users commonly either run the entire suite or an individual
81+
# file, and it's useful to allow more verbose output when running an
82+
# individual spec file.
83+
if config.files_to_run.one?
84+
# Use the documentation formatter for detailed output,
85+
# unless a formatter has already been configured
86+
# (e.g. via a command-line flag).
87+
config.default_formatter = "doc"
88+
end
89+
90+
# Print the 10 slowest examples and example groups at the
91+
# end of the spec run, to help surface which specs are running
92+
# particularly slow.
93+
config.profile_examples = 10
94+
95+
# Run specs in random order to surface order dependencies. If you find an
96+
# order dependency and want to debug it, you can fix the order by providing
97+
# the seed, which is printed after each run.
98+
# --seed 1234
99+
config.order = :random
100+
101+
# Seed global randomization in this process using the `--seed` CLI option.
102+
# Setting this allows you to use `--seed` to deterministically reproduce
103+
# test failures related to randomization by passing the same `--seed` value
104+
# as the one that triggered the failure.
105+
Kernel.srand config.seed
106+
end

spec/static_asset_finder_spec.rb

Lines changed: 1 addition & 1 deletion
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
RSpec.describe InlineSvg::StaticAssetFinder do
66
context "when the file is not found" do

spec/transformation_pipeline/transformations/aria_attributes_spec.rb

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

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

55
RSpec.describe InlineSvg::TransformPipeline::Transformations::AriaAttributes do
66
it "adds a role attribute to the SVG document" do

spec/transformation_pipeline/transformations/aria_hidden_attribute_spec.rb

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

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

55
RSpec.describe InlineSvg::TransformPipeline::Transformations::AriaHiddenAttribute do
66
it "adds an aria-hidden='true' attribute to a SVG document" do

spec/transformation_pipeline/transformations/class_attribute_spec.rb

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

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

55
RSpec.describe InlineSvg::TransformPipeline::Transformations::ClassAttribute do
66
it "adds a class attribute to a SVG document" do

spec/transformation_pipeline/transformations/data_attributes_spec.rb

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

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

55
RSpec.describe InlineSvg::TransformPipeline::Transformations::DataAttributes do
66
it "adds a data attribute to a SVG document" do

spec/transformation_pipeline/transformations/description_spec.rb

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

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

55
RSpec.describe InlineSvg::TransformPipeline::Transformations::Description do
66
it "adds a desc element to the SVG document" do

spec/transformation_pipeline/transformations/height_spec.rb

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

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

55
RSpec.describe InlineSvg::TransformPipeline::Transformations::Height do
66
it "adds height attribute to a SVG document" do

spec/transformation_pipeline/transformations/id_attribute_spec.rb

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

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

55
RSpec.describe InlineSvg::TransformPipeline::Transformations::IdAttribute do
66
it "adds an id attribute to a SVG document" do

spec/transformation_pipeline/transformations/preserve_aspect_ratio_spec.rb

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

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

55
RSpec.describe InlineSvg::TransformPipeline::Transformations::PreserveAspectRatio do
66
it "adds preserveAspectRatio attribute to a SVG document" do

spec/transformation_pipeline/transformations/size_spec.rb

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

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

55
RSpec.describe InlineSvg::TransformPipeline::Transformations::Size do
66
it "adds width and height attributes to a SVG document" do

spec/transformation_pipeline/transformations/style_attribute_spec.rb

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

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

55
RSpec.describe InlineSvg::TransformPipeline::Transformations::ClassAttribute do
66
it "adds a style attribute to a SVG document" do

spec/transformation_pipeline/transformations/title_spec.rb

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

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

55
RSpec.describe InlineSvg::TransformPipeline::Transformations::Title do
66
it "adds a title element as the first element in the SVG document" do

spec/transformation_pipeline/transformations/transformation_spec.rb

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

3-
require 'inline_svg'
4-
require 'inline_svg/transform_pipeline'
3+
require 'spec_helper'
54

65
RSpec.describe InlineSvg::TransformPipeline::Transformations::Transformation do
76
describe "#with_svg" do

spec/transformation_pipeline/transformations/view_box_spec.rb

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

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

55
RSpec.describe InlineSvg::TransformPipeline::Transformations::ViewBox do
66
it "adds viewBox attribute to a SVG document" do

spec/transformation_pipeline/transformations/width_spec.rb

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

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

55
RSpec.describe InlineSvg::TransformPipeline::Transformations::Width do
66
it "adds width attribute to a SVG document" do

spec/transformation_pipeline/transformations_spec.rb

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

3-
require 'inline_svg'
4-
require 'inline_svg/transform_pipeline'
3+
require 'spec_helper'
54

65
class ACustomTransform < InlineSvg::CustomTransformation
76
def transform(doc)

spec/webpack_asset_finder_spec.rb

Lines changed: 1 addition & 1 deletion
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
RSpec.describe InlineSvg::WebpackAssetFinder do
66
context "when the file is not found" do

0 commit comments

Comments
 (0)