rematch 1.4.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f699e5e0c1d64349c09caa39f25bbacb14611337ab42a96f648869bebdb76a0c
4
- data.tar.gz: ecfb4cca03ca59e1d7e48678cc5a275638b8274afa3ea86e46cb2489fc1baeed
3
+ metadata.gz: e4215339cb95a5fa7ecc1973a0941c0f25c6246fc13ac9b8df167d84100899db
4
+ data.tar.gz: 8ff79fd882236eff9ca9c874b9b447f4f8309206a221ce720620d1a31e2f112a
5
5
  SHA512:
6
- metadata.gz: be3f22dcd4354450f4e540eb1102813b681e0b06a4b241db47be3d4bb56cbb94e26ed0610921e3143ea56e23fff5638bad7c0f0a73f89735bd300bb0eece75d2
7
- data.tar.gz: ba28a07503d7ab0f3c8c362a5b7117cddeb8efde244041c5b9e82ba8f5137b5aabbad4166d79870d1c9a336e860da4fad62ad74e856105e84bad6ad0d32f4d63
6
+ metadata.gz: 30090d94864f2fc45082671d94bef638a9c6611576642c7345c38ae28d72d9cf509832203ecff243a809a944b86db94c8c23aff82d7124710738fc66353cae11
7
+ data.tar.gz: 63ed9212a5a0d3cddaa0b9d99301d29e4c4fe40abee1e339bb87551898b22502a0e8250c4eb44ef1cdfba9526d774d917978d29a86ce53313ac960b5cbfa812f
@@ -23,16 +23,20 @@ module Minitest
23
23
  # Reopen the minitest module
24
24
  module Assertions
25
25
  # Main assertion
26
- def assert_rematch(actual, *args)
26
+ def assert_rematch(key, actual, *args)
27
27
  assertion = :assert_equal
28
28
  message = nil
29
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
30
+ if actual.nil? # use specific assert_nil after deprecation of assert_equal nil
31
+ assert_nil @rematch.rematch(key, actual), message
32
+ else
33
+ send assertion, @rematch.rematch(key, actual), actual, message # assert that the stored value is the same actual value
34
+ end
31
35
  end
32
36
 
33
37
  # 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)
38
+ def store_assert_rematch(key, actual, *_args)
39
+ @rematch.store(key, actual)
36
40
  # Always fail after storing, forcing the restore of the original assertion/expectation
37
41
  raise Minitest::Assertion, '[rematch] the value has been stored: remove the "store_" prefix to pass the test'
38
42
  end
@@ -41,7 +45,7 @@ module Minitest
41
45
  # Reopen the minitest module
42
46
  module Expectations
43
47
  # Add the expectations pointing to the assertions
44
- infect_an_assertion :assert_rematch, :must_rematch, true # dont_flip
45
- infect_an_assertion :store_assert_rematch, :store_must_rematch, true # dont_flip
48
+ infect_an_assertion :assert_rematch, :must_rematch
49
+ infect_an_assertion :store_assert_rematch, :store_must_rematch
46
50
  end
47
51
  end
data/lib/rematch.rb CHANGED
@@ -5,7 +5,7 @@ require 'fileutils'
5
5
 
6
6
  # Handles the key/value store for each test
7
7
  class Rematch
8
- VERSION = '1.4.2'
8
+ VERSION = '2.1.0'
9
9
  EXT = '.rematch'
10
10
 
11
11
  @rebuild = false # rebuild the store?
@@ -29,24 +29,34 @@ class Rematch
29
29
  self.class.check_rebuild(path)
30
30
  @store = YAML::Store.new(path, true)
31
31
  @id = id
32
- @count = 0
33
32
  end
34
33
 
35
34
  # Retrieve the stored value for the current assertion if its key is known; store the value otherwise
36
- def rematch(value)
37
- key = assertion_key
38
- @store.transaction { |s| s.root?(key) ? s[key] : s[key] = value }
35
+ def rematch(key, value)
36
+ # key = assertion_key(key)
37
+ @store.transaction do |s|
38
+ if s.root?(@id) # there is the root id
39
+ if s[@id].key?(key) # there is the key
40
+ s[@id][key] # return it
41
+ else # not such a key
42
+ s[@id][key] = value # set
43
+ end
44
+ else # there is no root yet
45
+ s[@id] = { key => value } # the key is the first one
46
+ value # always return the value
47
+ end
48
+ end
39
49
  end
40
50
 
41
51
  # 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}"
52
+ def store(key, value)
53
+ @store.transaction do |s|
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
51
61
  end
52
62
  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.2
4
+ version: 2.1.0
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 00:00:00.000000000 Z
11
+ date: 2024-02-07 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
@@ -38,14 +38,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">"
40
40
  - !ruby/object:Gem::Version
41
- version: '2.5'
41
+ version: '3.1'
42
42
  required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  requirements: []
48
- rubygems_version: 3.2.32
48
+ rubygems_version: 3.5.3
49
49
  signing_key:
50
50
  specification_version: 4
51
51
  summary: Declutter your test files from large hardcoded data and update them automatically