rematch 1.3.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/minitest/rematch_plugin.rb +16 -4
- data/lib/rematch.rb +20 -6
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f699e5e0c1d64349c09caa39f25bbacb14611337ab42a96f648869bebdb76a0c
|
4
|
+
data.tar.gz: ecfb4cca03ca59e1d7e48678cc5a275638b8274afa3ea86e46cb2489fc1baeed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be3f22dcd4354450f4e540eb1102813b681e0b06a4b241db47be3d4bb56cbb94e26ed0610921e3143ea56e23fff5638bad7c0f0a73f89735bd300bb0eece75d2
|
7
|
+
data.tar.gz: ba28a07503d7ab0f3c8c362a5b7117cddeb8efde244041c5b9e82ba8f5137b5aabbad4166d79870d1c9a336e860da4fad62ad74e856105e84bad6ad0d32f4d63
|
@@ -4,32 +4,44 @@ require 'rematch'
|
|
4
4
|
|
5
5
|
# Implement the minitest plugin
|
6
6
|
module Minitest
|
7
|
+
# Set Rematch.rebuild with the --rematch-rebuild
|
7
8
|
def self.plugin_rematch_options(opts, _options)
|
8
9
|
opts.on '--rematch-rebuild', 'Rebuild the stores with the current entries/values' do
|
9
10
|
Rematch.rebuild = true
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
|
-
#
|
14
|
+
# Reopen the minitest class
|
14
15
|
class Test
|
16
|
+
# Create the rematch object for each test
|
15
17
|
def before_setup
|
16
18
|
super
|
17
19
|
@rematch = Rematch.new(path: method(name).source_location.first, id: location)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
|
-
#
|
23
|
+
# Reopen the minitest module
|
22
24
|
module Assertions
|
25
|
+
# Main assertion
|
23
26
|
def assert_rematch(actual, *args)
|
24
27
|
assertion = :assert_equal
|
25
28
|
message = nil
|
26
29
|
args.each { |arg| arg.is_a?(Symbol) ? assertion = arg : message = arg }
|
27
|
-
send assertion, @rematch.rematch(actual), actual, message
|
30
|
+
send assertion, @rematch.rematch(actual), actual, message # assert that the stored value is the same actual value
|
31
|
+
end
|
32
|
+
|
33
|
+
# Temporarily used to store the actual value, useful for reconciliation of expected changed values
|
34
|
+
def store_assert_rematch(actual, *_args)
|
35
|
+
@rematch.store(actual)
|
36
|
+
# Always fail after storing, forcing the restore of the original assertion/expectation
|
37
|
+
raise Minitest::Assertion, '[rematch] the value has been stored: remove the "store_" prefix to pass the test'
|
28
38
|
end
|
29
39
|
end
|
30
40
|
|
31
|
-
#
|
41
|
+
# Reopen the minitest module
|
32
42
|
module Expectations
|
43
|
+
# Add the expectations pointing to the assertions
|
33
44
|
infect_an_assertion :assert_rematch, :must_rematch, true # dont_flip
|
45
|
+
infect_an_assertion :store_assert_rematch, :store_must_rematch, true # dont_flip
|
34
46
|
end
|
35
47
|
end
|
data/lib/rematch.rb
CHANGED
@@ -3,15 +3,17 @@
|
|
3
3
|
require 'yaml/store'
|
4
4
|
require 'fileutils'
|
5
5
|
|
6
|
-
#
|
6
|
+
# Handles the key/value store for each test
|
7
7
|
class Rematch
|
8
|
-
VERSION = '1.
|
8
|
+
VERSION = '1.4.2'
|
9
9
|
EXT = '.rematch'
|
10
10
|
|
11
|
-
@
|
11
|
+
@rebuild = false # rebuild the store?
|
12
|
+
@rebuilt = [] # paths already rebuilt
|
12
13
|
class << self
|
13
14
|
attr_accessor :rebuild
|
14
15
|
|
16
|
+
# Check whether path requires rebuild and do it if required
|
15
17
|
def check_rebuild(path)
|
16
18
|
return unless @rebuild && !@rebuilt.include?(path)
|
17
19
|
|
@@ -21,7 +23,7 @@ class Rematch
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
|
-
# path and unique id of the test being run
|
26
|
+
# Instantiated at each test, stores the path and the unique id of the test being run
|
25
27
|
def initialize(path:, id:)
|
26
28
|
path = "#{path}#{EXT}"
|
27
29
|
self.class.check_rebuild(path)
|
@@ -30,9 +32,21 @@ class Rematch
|
|
30
32
|
@count = 0
|
31
33
|
end
|
32
34
|
|
33
|
-
#
|
35
|
+
# Retrieve the stored value for the current assertion if its key is known; store the value otherwise
|
34
36
|
def rematch(value)
|
35
|
-
key =
|
37
|
+
key = assertion_key
|
36
38
|
@store.transaction { |s| s.root?(key) ? s[key] : s[key] = value }
|
37
39
|
end
|
40
|
+
|
41
|
+
# Store the value
|
42
|
+
def store(value)
|
43
|
+
@store.transaction { |s| s[assertion_key] = value }
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Return the key for the current assertion
|
49
|
+
def assertion_key
|
50
|
+
"[#{@count += 1}] #{@id}"
|
51
|
+
end
|
38
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rematch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domizio Demichelis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Instead of copying and pasting large outputs or big ruby structures into
|
14
14
|
all the affected test files every time your code change, you can do it the easy
|
@@ -25,7 +25,11 @@ files:
|
|
25
25
|
homepage: https://github.com/ddnexus/rematch
|
26
26
|
licenses:
|
27
27
|
- MIT
|
28
|
-
metadata:
|
28
|
+
metadata:
|
29
|
+
rubygems_mfa_required: 'true'
|
30
|
+
homepage_uri: https://github.com/ddnexus/rematch
|
31
|
+
bug_tracker_uri: https://github.com/ddnexus/rematch/issues
|
32
|
+
changelog_uri: https://github.com/ddnexus/rematch/blob/master/CHANGELOG.md
|
29
33
|
post_install_message:
|
30
34
|
rdoc_options: []
|
31
35
|
require_paths:
|
@@ -34,14 +38,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
38
|
requirements:
|
35
39
|
- - ">"
|
36
40
|
- !ruby/object:Gem::Version
|
37
|
-
version: '2.
|
41
|
+
version: '2.5'
|
38
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
43
|
requirements:
|
40
44
|
- - ">="
|
41
45
|
- !ruby/object:Gem::Version
|
42
46
|
version: '0'
|
43
47
|
requirements: []
|
44
|
-
rubygems_version: 3.2.
|
48
|
+
rubygems_version: 3.2.32
|
45
49
|
signing_key:
|
46
50
|
specification_version: 4
|
47
51
|
summary: Declutter your test files from large hardcoded data and update them automatically
|