rematch 1.2.0 → 1.4.1
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 +20 -5
- 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: 2b3e156f501309072c0c57f782f4954d878d6fca881df21be60294d048e8499d
|
4
|
+
data.tar.gz: '09b2e677934c63c345dcd5df0aaa1d045136b2089f93abbc9e88c19109bfaddc'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae7b319799b53c0c459217113ca1bb2e4811cadcacf26f2bb5be127414d8e1064fe70a3dfd15ce691a3013016fb8b772168568e450913f6b09045fe5d4e469e4
|
7
|
+
data.tar.gz: 8124b42a3eaa69c37c10b8991f1d3a3eb13c4c70fc2ecde3908580eae388da11e18848a89848c9a2f4682c8f2903afd77f336e70753c33c0ae665c02213c3105
|
@@ -4,29 +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
|
23
|
-
|
24
|
-
|
25
|
+
# Main assertion
|
26
|
+
def assert_rematch(actual, *args)
|
27
|
+
assertion = :assert_equal
|
28
|
+
message = nil
|
29
|
+
args.each { |arg| arg.is_a?(Symbol) ? assertion = arg : message = arg }
|
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'
|
25
38
|
end
|
26
39
|
end
|
27
40
|
|
28
|
-
#
|
41
|
+
# Reopen the minitest module
|
29
42
|
module Expectations
|
43
|
+
# Add the expectations pointing to the assertions
|
30
44
|
infect_an_assertion :assert_rematch, :must_rematch, true # dont_flip
|
45
|
+
infect_an_assertion :store_assert_rematch, :store_must_rematch, true # dont_flip
|
31
46
|
end
|
32
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.1'
|
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.1
|
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-10 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/ddneus/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
|