rematch 1.4.0 → 1.4.1
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/lib/minitest/rematch_plugin.rb +7 -1
- data/lib/rematch.rb +11 -9
- metadata +5 -2
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,6 +4,7 @@ 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
|
@@ -12,6 +13,7 @@ module Minitest
|
|
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)
|
@@ -20,21 +22,25 @@ module Minitest
|
|
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 # assert that the stored value is the same
|
30
|
+
send assertion, @rematch.rematch(actual), actual, message # assert that the stored value is the same actual value
|
28
31
|
end
|
29
32
|
|
33
|
+
# Temporarily used to store the actual value, useful for reconciliation of expected changed values
|
30
34
|
def store_assert_rematch(actual, *_args)
|
31
35
|
@rematch.store(actual)
|
36
|
+
# Always fail after storing, forcing the restore of the original assertion/expectation
|
32
37
|
raise Minitest::Assertion, '[rematch] the value has been stored: remove the "store_" prefix to pass the test'
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
36
41
|
# Reopen the minitest module
|
37
42
|
module Expectations
|
43
|
+
# Add the expectations pointing to the assertions
|
38
44
|
infect_an_assertion :assert_rematch, :must_rematch, true # dont_flip
|
39
45
|
infect_an_assertion :store_assert_rematch, :store_must_rematch, true # dont_flip
|
40
46
|
end
|
data/lib/rematch.rb
CHANGED
@@ -3,13 +3,13 @@
|
|
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.4.
|
8
|
+
VERSION = '1.4.1'
|
9
9
|
EXT = '.rematch'
|
10
10
|
|
11
|
-
@rebuild = false
|
12
|
-
@rebuilt = []
|
11
|
+
@rebuild = false # rebuild the store?
|
12
|
+
@rebuilt = [] # paths already rebuilt
|
13
13
|
class << self
|
14
14
|
attr_accessor :rebuild
|
15
15
|
|
@@ -23,7 +23,7 @@ class Rematch
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
#
|
26
|
+
# Instantiated at each test, stores the path and the unique id of the test being run
|
27
27
|
def initialize(path:, id:)
|
28
28
|
path = "#{path}#{EXT}"
|
29
29
|
self.class.check_rebuild(path)
|
@@ -32,19 +32,21 @@ class Rematch
|
|
32
32
|
@count = 0
|
33
33
|
end
|
34
34
|
|
35
|
-
# Retrieve the stored value
|
35
|
+
# Retrieve the stored value for the current assertion if its key is known; store the value otherwise
|
36
36
|
def rematch(value)
|
37
|
-
key =
|
37
|
+
key = assertion_key
|
38
38
|
@store.transaction { |s| s.root?(key) ? s[key] : s[key] = value }
|
39
39
|
end
|
40
40
|
|
41
|
+
# Store the value
|
41
42
|
def store(value)
|
42
|
-
@store.transaction { |s| s[
|
43
|
+
@store.transaction { |s| s[assertion_key] = value }
|
43
44
|
end
|
44
45
|
|
45
46
|
private
|
46
47
|
|
47
|
-
|
48
|
+
# Return the key for the current assertion
|
49
|
+
def assertion_key
|
48
50
|
"[#{@count += 1}] #{@id}"
|
49
51
|
end
|
50
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.
|
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-12-
|
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
|
@@ -27,6 +27,9 @@ licenses:
|
|
27
27
|
- MIT
|
28
28
|
metadata:
|
29
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
|
30
33
|
post_install_message:
|
31
34
|
rdoc_options: []
|
32
35
|
require_paths:
|