activesupport-cache-zstd_compressor 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +56 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rubocop.yml +20 -0
- data/.simplecov +22 -0
- data/Appraisals +13 -0
- data/Gemfile +20 -0
- data/Rakefile +30 -0
- data/bin/console +11 -0
- data/rubocop/layout.yml +29 -0
- data/rubocop/lint.yml +41 -0
- data/rubocop/metrics.yml +18 -0
- data/rubocop/naming.yml +4 -0
- data/rubocop/performance.yml +25 -0
- data/rubocop/rspec.yml +14 -0
- data/rubocop/style.yml +86 -0
- data/spec/active_support/cache/zstd_compressor/version_spec.rb +7 -0
- data/spec/active_support/cache/zstd_compressor/with_zlib_fallback_spec.rb +38 -0
- data/spec/active_support/cache/zstd_compressor_spec.rb +24 -0
- data/spec/spec_helper.rb +92 -0
- data/spec/support/compressor_behaviour.rb +37 -0
- data/spec/support/mutual-aid.muse +1639 -0
- data/tmp/.keep +0 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 85a9423aef7e7529d792c908ce158dea0c03b2923d442adccf5315830ec4ad36
|
4
|
+
data.tar.gz: a784981439fc2582a12f2ab9248acf36d743ff67896b7c3db765ce9b7e7a99bc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7a59a02b0d79c36256a738d3aa8c350ac6c784dba58eef85495c75225e5df63e868405dd6bd1d681745fabdcb7aa1b809355331d5470cc6ef5e4b33d26dc7ed
|
7
|
+
data.tar.gz: feefc9a98859b226ef9635f64e85ed658a90c71a3a2dd187a44b9f57edc4006e5b7087099e3e8ab9381f0d9dc026ffcfff9f05b95290e96e6a1829ca7d094340
|
@@ -0,0 +1,56 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ main ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ main ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
name: "test / ${{ matrix.ruby }}"
|
12
|
+
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
strategy:
|
16
|
+
fail-fast: false
|
17
|
+
matrix:
|
18
|
+
ruby: [ "3.2", "3.3", "3.4", head ]
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v4
|
22
|
+
|
23
|
+
- uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby }}
|
26
|
+
bundler-cache: true
|
27
|
+
|
28
|
+
- run: bundle exec rake test
|
29
|
+
|
30
|
+
- name: Upload coverage reports to Codecov
|
31
|
+
uses: codecov/codecov-action@v4
|
32
|
+
|
33
|
+
# See: https://github.com/orgs/community/discussions/26822#discussioncomment-3305794
|
34
|
+
test-finale:
|
35
|
+
name: "test"
|
36
|
+
|
37
|
+
runs-on: ubuntu-latest
|
38
|
+
if: ${{ always() }}
|
39
|
+
|
40
|
+
needs: [test]
|
41
|
+
|
42
|
+
steps:
|
43
|
+
- run: test "success" = "${{ needs.test.result }}"
|
44
|
+
|
45
|
+
lint:
|
46
|
+
runs-on: ubuntu-latest
|
47
|
+
|
48
|
+
steps:
|
49
|
+
- uses: actions/checkout@v4
|
50
|
+
|
51
|
+
- uses: ruby/setup-ruby@v1
|
52
|
+
with:
|
53
|
+
ruby-version: "3.4"
|
54
|
+
bundler-cache: true
|
55
|
+
|
56
|
+
- run: bundle exec rake lint
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
plugins:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rake
|
4
|
+
- rubocop-rspec
|
5
|
+
|
6
|
+
inherit_from:
|
7
|
+
- rubocop/layout.yml
|
8
|
+
- rubocop/lint.yml
|
9
|
+
- rubocop/metrics.yml
|
10
|
+
- rubocop/naming.yml
|
11
|
+
- rubocop/performance.yml
|
12
|
+
- rubocop/rspec.yml
|
13
|
+
- rubocop/style.yml
|
14
|
+
|
15
|
+
AllCops:
|
16
|
+
NewCops: enable
|
17
|
+
TargetRubyVersion: 3.2
|
18
|
+
Exclude:
|
19
|
+
- gemfiles/**/*
|
20
|
+
- vendor/**/*
|
data/.simplecov
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
SimpleCov.start do
|
4
|
+
gemfile = File.basename(ENV.fetch("BUNDLE_GEMFILE", "Gemfile"), ".gemfile").strip
|
5
|
+
gemfile = nil if gemfile.empty? || gemfile.casecmp?("gems.rb") || gemfile.casecmp?("Gemfile")
|
6
|
+
|
7
|
+
command_name ["#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}", gemfile].compact.join("/")
|
8
|
+
|
9
|
+
enable_coverage :branch
|
10
|
+
|
11
|
+
if ENV["CI"]
|
12
|
+
require "simplecov-cobertura"
|
13
|
+
formatter SimpleCov::Formatter::CoberturaFormatter
|
14
|
+
else
|
15
|
+
formatter SimpleCov::Formatter::MultiFormatter.new([
|
16
|
+
SimpleCov::Formatter::SimpleFormatter,
|
17
|
+
SimpleCov::Formatter::HTMLFormatter
|
18
|
+
])
|
19
|
+
end
|
20
|
+
|
21
|
+
add_filter "/spec/"
|
22
|
+
end
|
data/Appraisals
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
appraise "activesupport-7.1.x" do
|
4
|
+
gem "activesupport", "~> 7.1.0"
|
5
|
+
end
|
6
|
+
|
7
|
+
appraise "activesupport-7.2.x" do
|
8
|
+
gem "activesupport", "~> 7.2.0"
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise "activesupport-8.0.x" do
|
12
|
+
gem "activesupport", "~> 8.0.0"
|
13
|
+
end
|
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem "appraisal"
|
7
|
+
gem "rake"
|
8
|
+
|
9
|
+
gem "rspec"
|
10
|
+
|
11
|
+
gem "simplecov"
|
12
|
+
gem "simplecov-cobertura"
|
13
|
+
|
14
|
+
gem "rubocop", require: false
|
15
|
+
gem "rubocop-performance", require: false
|
16
|
+
gem "rubocop-rake", require: false
|
17
|
+
gem "rubocop-rspec", require: false
|
18
|
+
|
19
|
+
gem "debug"
|
20
|
+
gem "irb"
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
|
5
|
+
desc "Run tests"
|
6
|
+
task :test do
|
7
|
+
rm_rf "coverage"
|
8
|
+
rm_rf "gemfiles"
|
9
|
+
|
10
|
+
Bundler.with_unbundled_env do
|
11
|
+
sh "bundle exec appraisal generate"
|
12
|
+
|
13
|
+
# XXX: `bundle exec appraisal install` fails on ruby-3.2
|
14
|
+
Dir["gemfiles/*.gemfile"].each do |gemfile|
|
15
|
+
sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle lock")
|
16
|
+
sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle check") do |ok|
|
17
|
+
sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle install") unless ok
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
sh "bundle exec appraisal rspec --force-colour"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "Lint codebase"
|
26
|
+
task :lint do
|
27
|
+
sh "bundle exec rubocop --color"
|
28
|
+
end
|
29
|
+
|
30
|
+
task default: %i[test lint]
|
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "active_support/cache/zstd_compressor"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
require "irb"
|
11
|
+
IRB.start(__FILE__)
|
data/rubocop/layout.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Layout/ArgumentAlignment:
|
2
|
+
Enabled: true
|
3
|
+
EnforcedStyle: with_fixed_indentation
|
4
|
+
|
5
|
+
Layout/ClassStructure:
|
6
|
+
Enabled: true
|
7
|
+
|
8
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
9
|
+
Enabled: true
|
10
|
+
|
11
|
+
Layout/FirstArrayElementIndentation:
|
12
|
+
Enabled: true
|
13
|
+
EnforcedStyle: consistent
|
14
|
+
|
15
|
+
Layout/FirstHashElementIndentation:
|
16
|
+
Enabled: true
|
17
|
+
EnforcedStyle: consistent
|
18
|
+
|
19
|
+
Layout/HashAlignment:
|
20
|
+
Enabled: true
|
21
|
+
EnforcedHashRocketStyle: table
|
22
|
+
EnforcedColonStyle: table
|
23
|
+
|
24
|
+
Layout/SpaceAroundMethodCallOperator:
|
25
|
+
Enabled: true
|
26
|
+
|
27
|
+
Layout/MultilineMethodCallIndentation:
|
28
|
+
Enabled: true
|
29
|
+
EnforcedStyle: indented
|
data/rubocop/lint.yml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
Lint/BinaryOperatorWithIdenticalOperands:
|
2
|
+
Enabled: true
|
3
|
+
|
4
|
+
Lint/DeprecatedOpenSSLConstant:
|
5
|
+
Enabled: true
|
6
|
+
|
7
|
+
Lint/DuplicateElsifCondition:
|
8
|
+
Enabled: true
|
9
|
+
|
10
|
+
Lint/DuplicateRescueException:
|
11
|
+
Enabled: true
|
12
|
+
|
13
|
+
Lint/EmptyConditionalBody:
|
14
|
+
Enabled: true
|
15
|
+
|
16
|
+
Lint/FloatComparison:
|
17
|
+
Enabled: true
|
18
|
+
|
19
|
+
Lint/MissingSuper:
|
20
|
+
Enabled: true
|
21
|
+
|
22
|
+
Lint/MixedRegexpCaptureTypes:
|
23
|
+
Enabled: true
|
24
|
+
|
25
|
+
Lint/OutOfRangeRegexpRef:
|
26
|
+
Enabled: true
|
27
|
+
|
28
|
+
Lint/RaiseException:
|
29
|
+
Enabled: true
|
30
|
+
|
31
|
+
Lint/SelfAssignment:
|
32
|
+
Enabled: true
|
33
|
+
|
34
|
+
Lint/StructNewOverride:
|
35
|
+
Enabled: true
|
36
|
+
|
37
|
+
Lint/TopLevelReturnWithArgument:
|
38
|
+
Enabled: true
|
39
|
+
|
40
|
+
Lint/UnreachableLoop:
|
41
|
+
Enabled: true
|
data/rubocop/metrics.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Metrics/BlockLength:
|
2
|
+
Enabled: true
|
3
|
+
CountAsOne: [array, hash, heredoc, method_call]
|
4
|
+
Exclude:
|
5
|
+
- "spec/**/*_spec.rb"
|
6
|
+
- "**/*.gemspec"
|
7
|
+
|
8
|
+
Metrics/ClassLength:
|
9
|
+
Enabled: true
|
10
|
+
CountAsOne: [array, hash, heredoc, method_call]
|
11
|
+
|
12
|
+
Metrics/MethodLength:
|
13
|
+
Enabled: true
|
14
|
+
CountAsOne: [array, hash, heredoc, method_call]
|
15
|
+
|
16
|
+
Metrics/ModuleLength:
|
17
|
+
Enabled: true
|
18
|
+
CountAsOne: [array, hash, heredoc, method_call]
|
data/rubocop/naming.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Performance/AncestorsInclude:
|
2
|
+
Enabled: true
|
3
|
+
|
4
|
+
Performance/BigDecimalWithNumericArgument:
|
5
|
+
Enabled: true
|
6
|
+
|
7
|
+
Performance/RedundantSortBlock:
|
8
|
+
Enabled: true
|
9
|
+
|
10
|
+
Performance/RedundantStringChars:
|
11
|
+
Enabled: true
|
12
|
+
|
13
|
+
Performance/ReverseFirst:
|
14
|
+
Enabled: true
|
15
|
+
|
16
|
+
Performance/SortReverse:
|
17
|
+
Enabled: true
|
18
|
+
|
19
|
+
Performance/Squeeze:
|
20
|
+
Enabled: true
|
21
|
+
|
22
|
+
Performance/StringInclude:
|
23
|
+
Enabled: true
|
24
|
+
|
25
|
+
|
data/rubocop/rspec.yml
ADDED
data/rubocop/style.yml
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
Style/AccessorGrouping:
|
2
|
+
Enabled: true
|
3
|
+
|
4
|
+
Style/ArrayCoercion:
|
5
|
+
Enabled: true
|
6
|
+
|
7
|
+
Style/BisectedAttrAccessor:
|
8
|
+
Enabled: true
|
9
|
+
|
10
|
+
Style/CaseLikeIf:
|
11
|
+
Enabled: true
|
12
|
+
|
13
|
+
Style/Documentation:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/ExplicitBlockArgument:
|
17
|
+
Enabled: true
|
18
|
+
|
19
|
+
Style/ExponentialNotation:
|
20
|
+
Enabled: true
|
21
|
+
|
22
|
+
Style/GlobalStdStream:
|
23
|
+
Enabled: true
|
24
|
+
|
25
|
+
Style/HashAsLastArrayItem:
|
26
|
+
Enabled: true
|
27
|
+
|
28
|
+
Style/HashEachMethods:
|
29
|
+
Enabled: true
|
30
|
+
|
31
|
+
Style/HashLikeCase:
|
32
|
+
Enabled: true
|
33
|
+
|
34
|
+
Style/HashSyntax:
|
35
|
+
Enabled: true
|
36
|
+
|
37
|
+
Style/HashTransformKeys:
|
38
|
+
Enabled: true
|
39
|
+
|
40
|
+
Style/HashTransformValues:
|
41
|
+
Enabled: true
|
42
|
+
|
43
|
+
Style/OptionalBooleanParameter:
|
44
|
+
Enabled: true
|
45
|
+
|
46
|
+
Style/RedundantAssignment:
|
47
|
+
Enabled: true
|
48
|
+
|
49
|
+
Style/RedundantCurrentDirectoryInPath:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Style/RedundantFetchBlock:
|
53
|
+
Enabled: true
|
54
|
+
|
55
|
+
Style/RedundantFileExtensionInRequire:
|
56
|
+
Enabled: true
|
57
|
+
|
58
|
+
Style/RedundantRegexpCharacterClass:
|
59
|
+
Enabled: true
|
60
|
+
|
61
|
+
Style/RedundantRegexpEscape:
|
62
|
+
Enabled: true
|
63
|
+
|
64
|
+
Style/RegexpLiteral:
|
65
|
+
Enabled: true
|
66
|
+
EnforcedStyle: percent_r
|
67
|
+
|
68
|
+
Style/RescueStandardError:
|
69
|
+
Enabled: true
|
70
|
+
EnforcedStyle: explicit
|
71
|
+
|
72
|
+
Style/SingleArgumentDig:
|
73
|
+
Enabled: true
|
74
|
+
|
75
|
+
Style/SlicingWithRange:
|
76
|
+
Enabled: true
|
77
|
+
|
78
|
+
Style/StringConcatenation:
|
79
|
+
Enabled: true
|
80
|
+
|
81
|
+
Style/StringLiterals:
|
82
|
+
Enabled: true
|
83
|
+
EnforcedStyle: double_quotes
|
84
|
+
|
85
|
+
Style/YodaCondition:
|
86
|
+
Enabled: false
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "support/compressor_behaviour"
|
4
|
+
|
5
|
+
RSpec.describe ActiveSupport::Cache::ZstdCompressor::WithZlibFallback do
|
6
|
+
it_behaves_like "a compressor" do
|
7
|
+
describe "#inflate" do
|
8
|
+
it "is capable of inflating data compressed with Zlib" do
|
9
|
+
uncompressed = compressor.inflate(Zlib.deflate(FOOD_FOR_THOUGHT))
|
10
|
+
|
11
|
+
expect(uncompressed).to eq(FOOD_FOR_THOUGHT)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "itegrates perfectly" do
|
17
|
+
compressor = described_class.new
|
18
|
+
serializer = Marshal
|
19
|
+
cache = ActiveSupport::Cache.lookup_store(:memory_store, serializer:, compressor:, compress: true)
|
20
|
+
|
21
|
+
cache.write("example", { food_for_thought: FOOD_FOR_THOUGHT })
|
22
|
+
|
23
|
+
expect(cache.read("example")).to eq({ food_for_thought: FOOD_FOR_THOUGHT })
|
24
|
+
end
|
25
|
+
|
26
|
+
it "works with with Zlib legacy compressor nicely" do
|
27
|
+
compressor = described_class.new
|
28
|
+
serializer = Marshal
|
29
|
+
old_cache = ActiveSupport::Cache.lookup_store(:memory_store, serializer:, compress: true)
|
30
|
+
new_cache = ActiveSupport::Cache.lookup_store(:memory_store, serializer:, compressor:, compress: true)
|
31
|
+
|
32
|
+
old_cache.write("example", { food_for_thought: FOOD_FOR_THOUGHT })
|
33
|
+
|
34
|
+
new_cache.instance_variable_set(:@data, old_cache.instance_variable_get(:@data))
|
35
|
+
|
36
|
+
expect(new_cache.read("example")).to eq({ food_for_thought: FOOD_FOR_THOUGHT })
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "support/compressor_behaviour"
|
4
|
+
|
5
|
+
RSpec.describe ActiveSupport::Cache::ZstdCompressor do
|
6
|
+
it_behaves_like "a compressor" do
|
7
|
+
describe "#inflate" do
|
8
|
+
it "is uncapable of inflating data compressed with Zlib" do
|
9
|
+
expect { compressor.inflate(Zlib.deflate(FOOD_FOR_THOUGHT)) }
|
10
|
+
.to raise_error(%r{not compressed by zstd})
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "itegrates perfectly" do
|
16
|
+
compressor = described_class.new
|
17
|
+
serializer = Marshal
|
18
|
+
cache = ActiveSupport::Cache.lookup_store(:memory_store, serializer:, compressor:, compress: true)
|
19
|
+
|
20
|
+
cache.write("example", { food_for_thought: FOOD_FOR_THOUGHT })
|
21
|
+
|
22
|
+
expect(cache.read("example")).to eq({ food_for_thought: FOOD_FOR_THOUGHT })
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "activesupport-cache-zstd_compressor"
|
4
|
+
|
5
|
+
# Ensure project struture and Zeitwerk ara correct
|
6
|
+
ActiveSupport::Cache::ZstdCompressor::Loader.eager_load(force: true)
|
7
|
+
|
8
|
+
require "active_support/cache"
|
9
|
+
require "active_support/notifications"
|
10
|
+
|
11
|
+
FOOD_FOR_THOUGHT = File.binread("#{__dir__}/support/mutual-aid.muse").freeze
|
12
|
+
|
13
|
+
# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
14
|
+
RSpec.configure do |config|
|
15
|
+
# rspec-expectations config goes here. You can use an alternate
|
16
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
17
|
+
# assertions if you prefer.
|
18
|
+
config.expect_with :rspec do |expectations|
|
19
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
20
|
+
# and `failure_message` of custom matchers include text for helper methods
|
21
|
+
# defined using `chain`, e.g.:
|
22
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
23
|
+
# # => "be bigger than 2 and smaller than 4"
|
24
|
+
# ...rather than:
|
25
|
+
# # => "be bigger than 2"
|
26
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
27
|
+
end
|
28
|
+
|
29
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
30
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
31
|
+
config.mock_with :rspec do |mocks|
|
32
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
33
|
+
# a real object. This is generally recommended, and will default to
|
34
|
+
# `true` in RSpec 4.
|
35
|
+
mocks.verify_partial_doubles = true
|
36
|
+
end
|
37
|
+
|
38
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
39
|
+
# have no way to turn it off -- the option exists only for backwards
|
40
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
41
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
42
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
43
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
44
|
+
|
45
|
+
# This allows you to limit a spec run to individual examples or groups
|
46
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
47
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
48
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
49
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
50
|
+
config.filter_run_when_matching :focus
|
51
|
+
|
52
|
+
# Allows RSpec to persist some state between runs in order to support
|
53
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
54
|
+
# you configure your source control system to ignore this file.
|
55
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
56
|
+
|
57
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
58
|
+
# recommended. For more details, see:
|
59
|
+
# https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
|
60
|
+
config.disable_monkey_patching!
|
61
|
+
|
62
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
63
|
+
# be too noisy due to issues in dependencies.
|
64
|
+
config.warnings = true
|
65
|
+
|
66
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
67
|
+
# file, and it's useful to allow more verbose output when running an
|
68
|
+
# individual spec file.
|
69
|
+
if config.files_to_run.one?
|
70
|
+
# Use the documentation formatter for detailed output,
|
71
|
+
# unless a formatter has already been configured
|
72
|
+
# (e.g. via a command-line flag).
|
73
|
+
config.default_formatter = "doc"
|
74
|
+
end
|
75
|
+
|
76
|
+
# Print the 10 slowest examples and example groups at the
|
77
|
+
# end of the spec run, to help surface which specs are running
|
78
|
+
# particularly slow.
|
79
|
+
config.profile_examples = 10
|
80
|
+
|
81
|
+
# Run specs in random order to surface order dependencies. If you find an
|
82
|
+
# order dependency and want to debug it, you can fix the order by providing
|
83
|
+
# the seed, which is printed after each run.
|
84
|
+
# --seed 1234
|
85
|
+
config.order = :random
|
86
|
+
|
87
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
88
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
89
|
+
# test failures related to randomization by passing the same `--seed` value
|
90
|
+
# as the one that triggered the failure.
|
91
|
+
Kernel.srand config.seed
|
92
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.shared_examples "a compressor" do
|
4
|
+
subject(:compressor) { described_class.new }
|
5
|
+
|
6
|
+
describe ".new" do
|
7
|
+
it "initializes compressor with default compression level=3" do
|
8
|
+
expect(described_class.new.level).to eq 3
|
9
|
+
end
|
10
|
+
|
11
|
+
it "allows setting different compression level" do
|
12
|
+
expect(described_class.new(level: 6).level).to eq(6)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "requires level to be an Integer" do
|
16
|
+
expect { described_class.new(level: "high") }
|
17
|
+
.to raise_error(ArgumentError, "Compression level must be an Integer")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#deflate" do
|
22
|
+
it "compresses data using Zstd" do
|
23
|
+
compressed = compressor.deflate(FOOD_FOR_THOUGHT)
|
24
|
+
|
25
|
+
expect(compressed).not_to eq(FOOD_FOR_THOUGHT)
|
26
|
+
expect(compressed.bytesize).to be < FOOD_FOR_THOUGHT.bytesize
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#inflate" do
|
31
|
+
it "uncompresses data using Zstd" do
|
32
|
+
uncompressed = compressor.inflate(compressor.deflate(FOOD_FOR_THOUGHT))
|
33
|
+
|
34
|
+
expect(uncompressed).to eq(FOOD_FOR_THOUGHT)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|