rspec-snapshot 2.0.2 → 2.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 +4 -4
- data/.github/workflows/ci.yml +8 -7
- data/.rubocop.yml +9 -5
- data/.ruby-version +1 -1
- data/Gemfile +6 -5
- data/MIGRATION_GUIDE.md +77 -0
- data/README.md +15 -6
- data/lib/rspec/snapshot/configuration.rb +5 -0
- data/lib/rspec/snapshot/default_serializer.rb +30 -3
- data/lib/rspec/snapshot/file_operator.rb +4 -2
- data/lib/rspec/snapshot/version.rb +1 -1
- data/rspec-snapshot.gemspec +2 -2
- metadata +10 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c7f958916acb3c3b0baca23b0787d2eba8b8fcc0ec66d48a279c374f50f1a759
|
|
4
|
+
data.tar.gz: 0d176ce77bb5ec147e1225711844d980fb3827e4dc4424b14e8fe2cfcad90f19
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9a6428ba725307cf97400503f5a0dbce9d6678a40ee31781c0435d843e3b915993f965673f6a2aec1a3a32c9a6214a44e8fbd471e93311af0584f749bea46af2
|
|
7
|
+
data.tar.gz: 0f0410cc159a5c3e394572d52c75335822ed2eec184f50e11ab5d4c314510e89c3c99990cbebf794cbdb78e1c8ecafa7afaf6a811848830ccc1187cfc0ecac99
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
on:
|
|
2
2
|
push:
|
|
3
|
+
pull_request:
|
|
3
4
|
|
|
4
5
|
jobs:
|
|
5
6
|
lint:
|
|
6
7
|
runs-on: ubuntu-latest
|
|
7
8
|
strategy:
|
|
8
9
|
matrix:
|
|
9
|
-
ruby-version: ['
|
|
10
|
+
ruby-version: ['4.0', '3.4', '3.3']
|
|
10
11
|
defaults:
|
|
11
12
|
run:
|
|
12
13
|
shell: bash
|
|
13
14
|
steps:
|
|
14
15
|
- uses: actions/checkout@v4
|
|
15
|
-
- uses: ruby/setup-ruby@
|
|
16
|
+
- uses: ruby/setup-ruby@ba696adf55506673e48342a66e30f1f53cadeae0
|
|
16
17
|
with:
|
|
17
18
|
ruby-version: ${{ matrix.ruby-version }}
|
|
18
|
-
- run: gem install bundler:
|
|
19
|
+
- run: gem install bundler:4.0.9
|
|
19
20
|
- run: bundle install
|
|
20
21
|
- run: bundle exec rubocop
|
|
21
22
|
|
|
@@ -24,16 +25,16 @@ jobs:
|
|
|
24
25
|
runs-on: ubuntu-latest
|
|
25
26
|
strategy:
|
|
26
27
|
matrix:
|
|
27
|
-
ruby-version: ['
|
|
28
|
+
ruby-version: ['4.0', '3.4', '3.3']
|
|
28
29
|
defaults:
|
|
29
30
|
run:
|
|
30
31
|
shell: bash
|
|
31
32
|
steps:
|
|
32
33
|
- uses: actions/checkout@v4
|
|
33
|
-
- uses: ruby/setup-ruby@
|
|
34
|
+
- uses: ruby/setup-ruby@ba696adf55506673e48342a66e30f1f53cadeae0
|
|
34
35
|
with:
|
|
35
36
|
ruby-version: ${{ matrix.ruby-version }}
|
|
36
|
-
- run: gem install bundler:
|
|
37
|
+
- run: gem install bundler:4.0.9
|
|
37
38
|
- run: bundle install
|
|
38
39
|
- run: cat Gemfile.lock
|
|
39
|
-
- run: bundle exec rspec
|
|
40
|
+
- run: bundle exec rspec
|
data/.rubocop.yml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
plugins:
|
|
2
2
|
- rubocop-rake
|
|
3
3
|
- rubocop-rspec
|
|
4
4
|
|
|
@@ -9,7 +9,7 @@ AllCops:
|
|
|
9
9
|
- "Rakefile"
|
|
10
10
|
- "bin/**/*"
|
|
11
11
|
- "spec/fixtures/**/*"
|
|
12
|
-
TargetRubyVersion:
|
|
12
|
+
TargetRubyVersion: 3.3
|
|
13
13
|
|
|
14
14
|
Layout/EmptyLinesAroundAttributeAccessor:
|
|
15
15
|
Enabled: true
|
|
@@ -42,10 +42,14 @@ RSpec/ContextWording:
|
|
|
42
42
|
- and
|
|
43
43
|
RSpec/ExampleLength:
|
|
44
44
|
Enabled: true
|
|
45
|
-
Max:
|
|
45
|
+
Max: 15 # Increased for integration tests
|
|
46
46
|
RSpec/ExpectInHook:
|
|
47
|
+
Enabled: false # Disabled to allow expect in setup for integration tests
|
|
48
|
+
RSpec/ExpectInLet:
|
|
49
|
+
Enabled: false # Disabled to balance style guidelines with testing ease
|
|
50
|
+
RSpec/SpecFilePathFormat:
|
|
47
51
|
Enabled: true
|
|
48
|
-
RSpec/
|
|
52
|
+
RSpec/SpecFilePathSuffix:
|
|
49
53
|
Enabled: true
|
|
50
54
|
RSpec/InstanceVariable:
|
|
51
55
|
Enabled: true
|
|
@@ -56,7 +60,7 @@ RSpec/LetSetup:
|
|
|
56
60
|
RSpec/MessageSpies:
|
|
57
61
|
Enabled: true
|
|
58
62
|
RSpec/MultipleExpectations:
|
|
59
|
-
|
|
63
|
+
Max: 5 # Increased for integration tests that verify multiple aspects
|
|
60
64
|
RSpec/MultipleMemoizedHelpers:
|
|
61
65
|
Enabled: false
|
|
62
66
|
RSpec/NamedSubject:
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.
|
|
1
|
+
3.4.2
|
data/Gemfile
CHANGED
|
@@ -4,11 +4,12 @@ source 'https://rubygems.org'
|
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
6
|
# Development dependencies
|
|
7
|
-
gem 'bundler', '~>
|
|
7
|
+
gem 'bundler', '~> 4.0'
|
|
8
8
|
gem 'byebug'
|
|
9
|
+
gem 'logger' # Required for Ruby 4.0+ (no longer in stdlib)
|
|
9
10
|
gem 'pry-byebug'
|
|
10
11
|
gem 'rake', '~> 13.0'
|
|
11
|
-
gem 'rubocop', '~> 1.
|
|
12
|
-
gem 'rubocop-rake', '~> 0.6
|
|
13
|
-
gem 'rubocop-rspec', '~>
|
|
14
|
-
gem 'simplecov'
|
|
12
|
+
gem 'rubocop', '~> 1.86'
|
|
13
|
+
gem 'rubocop-rake', '~> 0.6'
|
|
14
|
+
gem 'rubocop-rspec', '~> 3.0'
|
|
15
|
+
gem 'simplecov'
|
data/MIGRATION_GUIDE.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Migration Guide: awesome_print to amazing_print
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Starting with version 2.1.0, rspec-snapshot has migrated from `awesome_print` to `amazing_print`. The `amazing_print` gem is an actively maintained fork of `awesome_print`, which is no longer maintained.
|
|
6
|
+
|
|
7
|
+
## Backward Compatibility
|
|
8
|
+
|
|
9
|
+
**Good news!** You do **NOT** need to update your existing snapshots. The gem defaults to the classic hash syntax (`:foo => value`) for backward compatibility with existing snapshots created using `awesome_print`.
|
|
10
|
+
|
|
11
|
+
## Configuration Options
|
|
12
|
+
|
|
13
|
+
### Classic Syntax (Default)
|
|
14
|
+
|
|
15
|
+
By default, the gem uses classic hash rocket syntax to maintain compatibility with existing snapshots:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
{
|
|
19
|
+
:foo => {
|
|
20
|
+
:bar => [
|
|
21
|
+
[0] 1,
|
|
22
|
+
[1] 2,
|
|
23
|
+
[2] 3
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
:baz => true
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
This is the default behavior - no configuration needed.
|
|
31
|
+
|
|
32
|
+
### Modern Syntax (Optional)
|
|
33
|
+
|
|
34
|
+
If you want to use the modern Ruby 2.0+ hash syntax in your snapshots, you can opt-in by configuring RSpec:
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
RSpec.configure do |config|
|
|
38
|
+
config.snapshot_hash_syntax = :modern
|
|
39
|
+
end
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This will produce:
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
{
|
|
46
|
+
foo: {
|
|
47
|
+
bar: [
|
|
48
|
+
[0] 1,
|
|
49
|
+
[1] 2,
|
|
50
|
+
[2] 3
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
baz: true
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Note:** If you switch to modern syntax, you'll need to regenerate all your snapshots:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
UPDATE_SNAPSHOTS=true bundle exec rspec
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## For New Projects
|
|
64
|
+
|
|
65
|
+
New projects can choose either syntax style. We recommend using `:modern` syntax for new projects as it's more consistent with modern Ruby code style.
|
|
66
|
+
|
|
67
|
+
## Gem Compatibility
|
|
68
|
+
|
|
69
|
+
The gem will work with either `amazing_print` or `awesome_print`:
|
|
70
|
+
|
|
71
|
+
- If `amazing_print` is available, it will be used
|
|
72
|
+
- If only `awesome_print` is available, it will fall back to that
|
|
73
|
+
- The gem automatically handles the syntax conversion based on your configuration
|
|
74
|
+
|
|
75
|
+
## Questions?
|
|
76
|
+
|
|
77
|
+
If you have any issues with the migration, please open an issue on GitHub.
|
data/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
# RSpec::Snapshot
|
|
1
|
+
# RSpec::Snapshot 
|
|
2
2
|
|
|
3
3
|
Adds snapshot testing to RSpec, inspired by [Jest](https://jestjs.io/).
|
|
4
4
|
|
|
5
|
+
**This project is looking for a new maintainer, create an issue in the repo if you are interested.**
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
Add this line to your application's Gemfile:
|
|
@@ -154,12 +156,19 @@ Install a current version of ruby (> 2.5) and bundler. Then install gems
|
|
|
154
156
|
|
|
155
157
|
$ bin/console
|
|
156
158
|
|
|
157
|
-
###
|
|
159
|
+
### Installing the gem locally
|
|
160
|
+
|
|
161
|
+
$ bundle exec rake install
|
|
162
|
+
|
|
163
|
+
### Publishing a new gem version
|
|
158
164
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
165
|
+
* Update the version number in `version.rb`
|
|
166
|
+
* Ensure the changes to be published are merged to the master branch
|
|
167
|
+
* Checkout the master branch locally
|
|
168
|
+
* Run `bundle exec rake release`, which will:
|
|
169
|
+
* create a git tag for the version
|
|
170
|
+
* push git commits and tags
|
|
171
|
+
* push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
163
172
|
|
|
164
173
|
## Contributing
|
|
165
174
|
|
|
@@ -8,6 +8,11 @@ module RSpec
|
|
|
8
8
|
config.add_setting :snapshot_dir, default: :relative
|
|
9
9
|
|
|
10
10
|
config.add_setting :snapshot_serializer, default: nil
|
|
11
|
+
|
|
12
|
+
# Hash syntax style for serialized output
|
|
13
|
+
# :classic uses hash rockets (:foo => value) for backward compatibility
|
|
14
|
+
# :modern uses Ruby 2.0+ syntax (foo: value)
|
|
15
|
+
config.add_setting :snapshot_hash_syntax, default: :classic
|
|
11
16
|
end
|
|
12
17
|
end
|
|
13
18
|
|
|
@@ -1,16 +1,43 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
begin
|
|
4
|
+
require 'amazing_print'
|
|
5
|
+
PRINT_GEM = :amazing_print
|
|
6
|
+
rescue LoadError
|
|
7
|
+
require 'awesome_print'
|
|
8
|
+
PRINT_GEM = :awesome_print
|
|
9
|
+
end
|
|
4
10
|
|
|
5
11
|
module RSpec
|
|
6
12
|
module Snapshot
|
|
7
13
|
# Serializes values in a human readable way for snapshots using the
|
|
8
|
-
# awesome_print
|
|
14
|
+
# amazing_print gem (or awesome_print for backward compatibility)
|
|
9
15
|
class DefaultSerializer
|
|
10
16
|
# @param [*] value The value to serialize.
|
|
11
17
|
# @return [String] The serialized value.
|
|
12
18
|
def dump(value)
|
|
13
|
-
value.ai(plain: true, indent: 2)
|
|
19
|
+
output = value.ai(plain: true, indent: 2)
|
|
20
|
+
|
|
21
|
+
# Convert modern syntax to classic syntax for backward compatibility
|
|
22
|
+
if use_classic_syntax? && PRINT_GEM == :amazing_print
|
|
23
|
+
output = convert_to_classic_syntax(output)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
output
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def use_classic_syntax?
|
|
32
|
+
RSpec.configuration.snapshot_hash_syntax == :classic
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Converts modern Ruby hash syntax (foo:) to classic syntax (:foo =>)
|
|
36
|
+
# for backward compatibility with existing snapshots
|
|
37
|
+
def convert_to_classic_syntax(output)
|
|
38
|
+
# Match lines with symbol keys in modern syntax
|
|
39
|
+
# e.g., " foo: {" becomes " :foo => {"
|
|
40
|
+
output.gsub(/^(\s+)(\w+):(\s)/, '\1:\2 =>\3')
|
|
14
41
|
end
|
|
15
42
|
end
|
|
16
43
|
end
|
|
@@ -13,8 +13,8 @@ module RSpec
|
|
|
13
13
|
# @param [Hash] metadata The RSpec metadata for the current test.
|
|
14
14
|
def initialize(snapshot_name, metadata)
|
|
15
15
|
snapshot_dir = snapshot_dir(metadata)
|
|
16
|
-
create_snapshot_dir(snapshot_dir)
|
|
17
16
|
@snapshot_path = File.join(snapshot_dir, "#{snapshot_name}.snap")
|
|
17
|
+
create_snapshot_dir(@snapshot_path)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
private def snapshot_dir(metadata)
|
|
@@ -26,7 +26,9 @@ module RSpec
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
private def create_snapshot_dir(snapshot_dir)
|
|
29
|
-
|
|
29
|
+
return if Dir.exist?(File.dirname(snapshot_dir))
|
|
30
|
+
|
|
31
|
+
FileUtils.mkdir_p(File.dirname(snapshot_dir))
|
|
30
32
|
end
|
|
31
33
|
|
|
32
34
|
# @return [String] The snapshot file contents.
|
data/rspec-snapshot.gemspec
CHANGED
|
@@ -22,9 +22,9 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
23
23
|
spec.require_paths = ['lib']
|
|
24
24
|
|
|
25
|
-
spec.required_ruby_version = '>=
|
|
25
|
+
spec.required_ruby_version = '>= 3.3.0'
|
|
26
26
|
|
|
27
|
-
spec.add_dependency '
|
|
27
|
+
spec.add_dependency 'amazing_print', '~> 1.6'
|
|
28
28
|
spec.add_dependency 'rspec', '> 3.0.0'
|
|
29
29
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
30
30
|
end
|
metadata
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rspec-snapshot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mike Levin
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2026-04-03 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
13
|
+
name: amazing_print
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
|
-
- - "
|
|
16
|
+
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.
|
|
18
|
+
version: '1.6'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
|
-
- - "
|
|
23
|
+
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 1.
|
|
25
|
+
version: '1.6'
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
27
|
name: rspec
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -53,6 +52,7 @@ files:
|
|
|
53
52
|
- ".ruby-version"
|
|
54
53
|
- Gemfile
|
|
55
54
|
- LICENSE.md
|
|
55
|
+
- MIGRATION_GUIDE.md
|
|
56
56
|
- README.md
|
|
57
57
|
- Rakefile
|
|
58
58
|
- bin/console
|
|
@@ -70,7 +70,6 @@ licenses:
|
|
|
70
70
|
- MIT
|
|
71
71
|
metadata:
|
|
72
72
|
rubygems_mfa_required: 'true'
|
|
73
|
-
post_install_message:
|
|
74
73
|
rdoc_options: []
|
|
75
74
|
require_paths:
|
|
76
75
|
- lib
|
|
@@ -78,15 +77,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
78
77
|
requirements:
|
|
79
78
|
- - ">="
|
|
80
79
|
- !ruby/object:Gem::Version
|
|
81
|
-
version:
|
|
80
|
+
version: 3.3.0
|
|
82
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
82
|
requirements:
|
|
84
83
|
- - ">="
|
|
85
84
|
- !ruby/object:Gem::Version
|
|
86
85
|
version: '0'
|
|
87
86
|
requirements: []
|
|
88
|
-
rubygems_version: 3.
|
|
89
|
-
signing_key:
|
|
87
|
+
rubygems_version: 3.6.2
|
|
90
88
|
specification_version: 4
|
|
91
89
|
summary: RSpec Snapshot Matcher
|
|
92
90
|
test_files: []
|