rematch 3.0.0 → 3.2.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/LICENSE.txt +1 -1
- data/lib/minitest/rematch_plugin.rb +11 -4
- data/lib/rematch/store.rb +13 -0
- data/lib/rematch.rb +26 -28
- metadata +34 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d53eeaada3490407b3977d044320c853c8ebe446099a365c53457a83a34c2ecd
|
4
|
+
data.tar.gz: 289b892aad3fc9edb098751583d7c99882b21311b72bf9be173508266882d45d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2417bb23ed9c231c6e26fca90596171d004fa2010e75b886aed56b844a82fd4883f4d37244fd1edbd47ecdb415966fafa589501b1c992c7de4271274ef7bfd7a
|
7
|
+
data.tar.gz: a9f1a10ab07482c461ae189d7d89ab0a16dbac2dce1f7dd388bce6a40e2722215574158fe0298dd8426aec336d077d79a59390f1de441b1470de892e0a941834
|
data/LICENSE.txt
CHANGED
@@ -7,16 +7,23 @@ module Minitest
|
|
7
7
|
# Set Rematch.rebuild with the --rematch-rebuild
|
8
8
|
def self.plugin_rematch_options(opts, _options)
|
9
9
|
opts.on '--rematch-rebuild', 'Rebuild the stores with the current entries/values' do
|
10
|
-
Rematch.rebuild
|
10
|
+
Rematch.rebuild = true
|
11
|
+
Rematch.skip_warning = true
|
11
12
|
end
|
13
|
+
# :nocov:
|
14
|
+
opts.on '--rematch-skip-warning', 'Skip the warning on storing a new value' do
|
15
|
+
Rematch.skip_warning = true
|
16
|
+
end
|
17
|
+
# :nocov:
|
12
18
|
end
|
13
19
|
|
14
20
|
# Reopen the minitest class
|
15
21
|
class Test
|
16
22
|
# Create the rematch object for each test
|
17
|
-
def
|
23
|
+
def after_setup
|
18
24
|
super
|
19
|
-
@rematch = Rematch.new(path: method(name).source_location.first,
|
25
|
+
@rematch = Rematch.new(path: method(name).source_location.first,
|
26
|
+
id: location)
|
20
27
|
end
|
21
28
|
end
|
22
29
|
|
@@ -36,7 +43,7 @@ module Minitest
|
|
36
43
|
|
37
44
|
# Temporarily used to store the actual value, useful for reconciliation of expected changed values
|
38
45
|
def store_assert_rematch(key, actual, *_args)
|
39
|
-
@rematch.
|
46
|
+
@rematch.rematch(key, actual, overwrite: true)
|
40
47
|
# Always fail after storing, forcing the restore of the original assertion/expectation
|
41
48
|
raise Minitest::Assertion, '[rematch] the value has been stored: remove the "store_" prefix to pass the test'
|
42
49
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml/store'
|
4
|
+
|
5
|
+
class Rematch
|
6
|
+
# Subclass of YAML::Store
|
7
|
+
class Store < YAML::Store
|
8
|
+
# Use unsafe load, because tests are trusted content
|
9
|
+
def load(content)
|
10
|
+
YAML.unsafe_load(content) || {}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/rematch.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'yaml/store'
|
4
3
|
require 'fileutils'
|
4
|
+
require_relative 'rematch/store'
|
5
5
|
|
6
6
|
# Handles the key/value store for each test
|
7
7
|
class Rematch
|
8
|
-
VERSION = '3.
|
9
|
-
|
8
|
+
VERSION = '3.2.0'
|
9
|
+
CONFIG = { ext: '.yaml' } # rubocop:disable Style/MutableConstant
|
10
|
+
|
11
|
+
@rebuild = false # rebuild the store?
|
12
|
+
@rebuilt = [] # paths already rebuilt
|
13
|
+
@skip_warning = false
|
10
14
|
|
11
|
-
@rebuild = false # rebuild the store?
|
12
|
-
@rebuilt = [] # paths already rebuilt
|
13
15
|
class << self
|
14
|
-
attr_accessor :rebuild
|
16
|
+
attr_accessor :rebuild, :skip_warning
|
15
17
|
|
16
18
|
# Check whether path requires rebuild and do it if required
|
17
19
|
def check_rebuild(path)
|
@@ -25,38 +27,34 @@ class Rematch
|
|
25
27
|
|
26
28
|
# Instantiated at each test, stores the path and the unique id of the test being run
|
27
29
|
def initialize(path:, id:)
|
28
|
-
|
29
|
-
self.class.check_rebuild(
|
30
|
-
@store =
|
30
|
+
store_path = "#{path}#{CONFIG[:ext]}"
|
31
|
+
self.class.check_rebuild(store_path)
|
32
|
+
@store = Store.new(store_path, true)
|
31
33
|
@id = id.tr('#: ', '_') # easier key string for clumsy yaml parsers/highlighters
|
32
34
|
end
|
33
35
|
|
34
36
|
# Retrieve the stored value for the current assertion if its key is known; store the value otherwise
|
35
|
-
def rematch(key, value)
|
37
|
+
def rematch(key, value, overwrite: nil)
|
36
38
|
# key = assertion_key(key)
|
37
39
|
@store.transaction do |s|
|
38
|
-
if s.root?(@id)
|
39
|
-
if s[@id].key?(key)
|
40
|
-
s[@id][key]
|
41
|
-
else
|
42
|
-
s[@id][key] = value
|
40
|
+
if s.root?(@id) # there is the root id
|
41
|
+
if s[@id].key?(key) && !overwrite # there is the key and not overwrite
|
42
|
+
s[@id][key] # return it
|
43
|
+
else # not such a key
|
44
|
+
s[@id][key] = value # set it
|
45
|
+
store_warning(key) unless overwrite
|
46
|
+
value
|
43
47
|
end
|
44
|
-
else
|
45
|
-
s[@id] = { key => value }
|
46
|
-
|
48
|
+
else # there is no root yet
|
49
|
+
s[@id] = { key => value } # the key is the first one
|
50
|
+
store_warning(key)
|
51
|
+
value # always return the value
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
if s.root?(@id) # there is the root id
|
55
|
-
s[@id][key] = value # set
|
56
|
-
else # there is no root yet
|
57
|
-
s[@id] = { key => value } # the key is the first one
|
58
|
-
value # always return the value
|
59
|
-
end
|
60
|
-
end
|
56
|
+
def store_warning(key)
|
57
|
+
warn "Rematch stored new value for: #{key.inspect}\n#{@id}\n#{@store.path}\n\n" \
|
58
|
+
unless Rematch.skip_warning
|
61
59
|
end
|
62
60
|
end
|
metadata
CHANGED
@@ -1,15 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rematch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domizio Demichelis
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
10
|
+
date: 2025-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: logger
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: pstore
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
13
40
|
description: Instead of copying and pasting large outputs or big ruby structures into
|
14
41
|
all the affected test files every time your code change, you can do it the easy
|
15
42
|
way, possibly saving many hours of boring maintenance work!
|
@@ -22,6 +49,7 @@ files:
|
|
22
49
|
- LICENSE.txt
|
23
50
|
- lib/minitest/rematch_plugin.rb
|
24
51
|
- lib/rematch.rb
|
52
|
+
- lib/rematch/store.rb
|
25
53
|
homepage: https://github.com/ddnexus/rematch
|
26
54
|
licenses:
|
27
55
|
- MIT
|
@@ -30,7 +58,6 @@ metadata:
|
|
30
58
|
homepage_uri: https://github.com/ddnexus/rematch
|
31
59
|
bug_tracker_uri: https://github.com/ddnexus/rematch/issues
|
32
60
|
changelog_uri: https://github.com/ddnexus/rematch/blob/master/CHANGELOG.md
|
33
|
-
post_install_message:
|
34
61
|
rdoc_options: []
|
35
62
|
require_paths:
|
36
63
|
- lib
|
@@ -38,15 +65,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
65
|
requirements:
|
39
66
|
- - ">"
|
40
67
|
- !ruby/object:Gem::Version
|
41
|
-
version: '3.
|
68
|
+
version: '3.2'
|
42
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
70
|
requirements:
|
44
71
|
- - ">="
|
45
72
|
- !ruby/object:Gem::Version
|
46
73
|
version: '0'
|
47
74
|
requirements: []
|
48
|
-
rubygems_version: 3.
|
49
|
-
signing_key:
|
75
|
+
rubygems_version: 3.6.2
|
50
76
|
specification_version: 4
|
51
77
|
summary: Declutter your test files from large hardcoded data and update them automatically
|
52
78
|
when your code changes
|