rematch 4.0.0 → 4.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/lib/minitest/rematch_plugin.rb +12 -5
- data/lib/rematch.rb +8 -9
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 75263525e5c9f837c2308c800c6ddd0fa8efa1472dc32aaca3eab36d4ba20990
|
|
4
|
+
data.tar.gz: 734123f5f1ea481c6d1d8c31cddfa074483e5dbd7289e6f8965f33a724b0eb46
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3c54c23fd47f85a99f53c3d7deead137ce5b5fcfaa2559ce957c440f2f142246091fde3aa1b6a0407029377519f28751c45ce0f42a8abd02c035843121a857d3
|
|
7
|
+
data.tar.gz: d3f5337a74934922e9d889564dc67f18be1a7371a2c24df4699cedb764df30c5278cca25b7872192235c4b4a93b4f044cfbe6393ef4e12bcfa769d7f06dda3bd
|
|
@@ -30,19 +30,26 @@ module Minitest
|
|
|
30
30
|
module Assertions
|
|
31
31
|
# Main assertion
|
|
32
32
|
def assert_rematch(actual, *args)
|
|
33
|
+
# Extract options (id) if present
|
|
34
|
+
opts = args.last.is_a?(Hash) && args.last.key?(:id) ? args.pop : {}
|
|
35
|
+
id = opts[:id]
|
|
33
36
|
assertion = :assert_equal
|
|
34
37
|
message = nil
|
|
35
38
|
args.each { |arg| arg.is_a?(Symbol) ? assertion = arg : message = arg }
|
|
36
39
|
if actual.nil? # use specific assert_nil after deprecation of assert_equal nil
|
|
37
|
-
assert_nil @rematch.rematch(actual), message
|
|
40
|
+
assert_nil @rematch.rematch(actual, id: id), message
|
|
38
41
|
else
|
|
39
|
-
|
|
42
|
+
# assert that the stored value is the same actual value
|
|
43
|
+
send assertion, @rematch.rematch(actual, id: id), actual, message
|
|
40
44
|
end
|
|
41
45
|
end
|
|
42
46
|
|
|
43
47
|
# Temporarily used to store the actual value, useful for reconciliation of expected changed values
|
|
44
|
-
def store_assert_rematch(actual, *
|
|
45
|
-
|
|
48
|
+
def store_assert_rematch(actual, *args)
|
|
49
|
+
opts = args.last.is_a?(Hash) && args.last.key?(:id) ? args.pop : {}
|
|
50
|
+
id = opts[:id]
|
|
51
|
+
|
|
52
|
+
@rematch.rematch(actual, overwrite: true, id: id)
|
|
46
53
|
# Always fail after storing, forcing the restore of the original assertion/expectation
|
|
47
54
|
raise Minitest::Assertion, '[rematch] the value has been stored: remove the "store_" prefix to pass the test'
|
|
48
55
|
end
|
|
@@ -53,6 +60,6 @@ module Minitest
|
|
|
53
60
|
expectation_class.infect_an_assertion :assert_rematch, :must_rematch, :reverse
|
|
54
61
|
expectation_class.alias_method :to_rematch, :must_rematch # to use with expect().to_rematch
|
|
55
62
|
expectation_class.infect_an_assertion :store_assert_rematch, :store_must_rematch, :reverse
|
|
56
|
-
expectation_class.alias_method :store_to_rematch, :store_must_rematch
|
|
63
|
+
expectation_class.alias_method :store_to_rematch, :store_must_rematch
|
|
57
64
|
end
|
|
58
65
|
end
|
data/lib/rematch.rb
CHANGED
|
@@ -6,7 +6,7 @@ require_relative 'rematch/store'
|
|
|
6
6
|
|
|
7
7
|
# Handles the key/value store for each test
|
|
8
8
|
class Rematch
|
|
9
|
-
VERSION = '4.
|
|
9
|
+
VERSION = '4.1.0'
|
|
10
10
|
CONFIG = { ext: '.yaml' } # rubocop:disable Style/MutableConstant
|
|
11
11
|
|
|
12
12
|
@rebuild = false # rebuild the store?
|
|
@@ -36,8 +36,8 @@ class Rematch
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
# Retrieve the stored value for the current assertion if its key is known; store the value otherwise
|
|
39
|
-
def rematch(value, overwrite: nil)
|
|
40
|
-
key = assertion_key
|
|
39
|
+
def rematch(value, overwrite: nil, id: nil)
|
|
40
|
+
key = assertion_key(id)
|
|
41
41
|
@store.transaction do |s|
|
|
42
42
|
if s.root?(key) && !overwrite # there is the key and not overwrite
|
|
43
43
|
s[key] # return it
|
|
@@ -51,8 +51,7 @@ class Rematch
|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def store_warning(key)
|
|
54
|
-
warn "Rematch stored new value for: #{key.inspect}\n#{@store.path}\n\n"
|
|
55
|
-
unless Rematch.skip_warning
|
|
54
|
+
warn "Rematch stored new value for: #{key.inspect}\n#{@store.path}\n\n" unless Rematch.skip_warning
|
|
56
55
|
end
|
|
57
56
|
|
|
58
57
|
protected
|
|
@@ -64,10 +63,10 @@ class Rematch
|
|
|
64
63
|
|
|
65
64
|
private
|
|
66
65
|
|
|
67
|
-
# Generate the key based on the line number and test ID
|
|
68
|
-
def assertion_key
|
|
66
|
+
# Generate the key based on the line number, optional id, and test ID
|
|
67
|
+
def assertion_key(id)
|
|
69
68
|
line = caller_locations.find { |l| l.path == @path }&.lineno
|
|
70
|
-
|
|
69
|
+
%(L#{line}#{" [#{id}]" if id} #{@id})
|
|
71
70
|
end
|
|
72
71
|
|
|
73
72
|
# Ensure the keys are sorted by the order of the tests in the file
|
|
@@ -88,7 +87,7 @@ class Rematch
|
|
|
88
87
|
end
|
|
89
88
|
# Extract all data
|
|
90
89
|
data = store.roots.to_h { |key| [key, store.delete(key)] }
|
|
91
|
-
# Re-add data in the correct order, filter orphans and sort
|
|
90
|
+
# Re-add data in the correct order, filter orphans, and sort
|
|
92
91
|
data.select { |key, _| valid_ids.include?(key.split.last) }
|
|
93
92
|
.sort_by { |key, _| key[/L(\d+)/, 1].to_i }
|
|
94
93
|
.each { |key, value| store[key] = value }
|