rematch 3.0.0 → 3.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: b1c8f28666e75297ba7dfa84ba0432715976075f2a2e1699b145eea7f41789fc
4
- data.tar.gz: 39c024389c8ccdfd97627952719c2cd0004a69f906b50621e1a9ab9b230e2947
3
+ metadata.gz: eda4df7b006973089166c780f17fe7ce888a2fdc4b23f4666897f7b4a89fa9e5
4
+ data.tar.gz: c8ab36a9be7dee2706ddf3850feb864a27a4f2cb93c78bdea487aae2ba2bad52
5
5
  SHA512:
6
- metadata.gz: 20cce9b1ae1ee171648d98f8838370bf913100c6dd0d9ccb92af0bbfcd6c0d41a49471e18e78b4235c06151ab8500a23c5a15293b583cc2e141ea035ba8af11b
7
- data.tar.gz: dc681036308b31d4d08efe48813c3ffa0a5d8d71d326b6a2495df2ac4f3c00c295a1a45b288046b10d2d8b2069756e150d57f1ab904b247cbc606faae27d216b
6
+ metadata.gz: 8e38063d219a49f9aee6082ed4cb1710c69473863efded0691e3948fba9259aa8a676f46a1335c247e3a2d2132a44fe39d9826cdada8ee673699da49b1127aab
7
+ data.tar.gz: 5cfe12e89fc6a48fb25c070b6ec87572b634ba6770c4bea2cf46b7bb1de3385b363e7ebfe05019079a911b47110c0be2de7c0329c258054794a66579c5c530b6
@@ -7,16 +7,23 @@ module Minitest
7
7
  # Set Rematch.rebuild with the --rematch-rebuild
8
8
  def self.plugin_rematch_options(opts, _options)
9
9
  opts.on '--rematch-rebuild', 'Rebuild the stores with the current entries/values' do
10
- Rematch.rebuild = true
10
+ Rematch.rebuild = true
11
+ Rematch.skip_warning = true
11
12
  end
13
+ # :nocov:
14
+ opts.on '--rematch-skip-warning', 'Skip the warning on storing a new value' do
15
+ Rematch.skip_warning = true
16
+ end
17
+ # :nocov:
12
18
  end
13
19
 
14
20
  # Reopen the minitest class
15
21
  class Test
16
22
  # Create the rematch object for each test
17
- def before_setup
23
+ def after_setup
18
24
  super
19
- @rematch = Rematch.new(path: method(name).source_location.first, id: location)
25
+ @rematch = Rematch.new(path: method(name).source_location.first,
26
+ id: location)
20
27
  end
21
28
  end
22
29
 
@@ -36,7 +43,7 @@ module Minitest
36
43
 
37
44
  # Temporarily used to store the actual value, useful for reconciliation of expected changed values
38
45
  def store_assert_rematch(key, actual, *_args)
39
- @rematch.store(key, actual)
46
+ @rematch.rematch(key, actual, overwrite: true)
40
47
  # Always fail after storing, forcing the restore of the original assertion/expectation
41
48
  raise Minitest::Assertion, '[rematch] the value has been stored: remove the "store_" prefix to pass the test'
42
49
  end
data/lib/rematch.rb CHANGED
@@ -5,13 +5,15 @@ require 'fileutils'
5
5
 
6
6
  # Handles the key/value store for each test
7
7
  class Rematch
8
- VERSION = '3.0.0'
9
- DEFAULT = { ext: '.yaml' } # rubocop:disable Style/MutableConstant
8
+ VERSION = '3.1.0'
9
+ CONFIG = { ext: '.yaml' } # rubocop:disable Style/MutableConstant
10
+
11
+ @rebuild = false # rebuild the store?
12
+ @rebuilt = [] # paths already rebuilt
13
+ @skip_warning = false
10
14
 
11
- @rebuild = false # rebuild the store?
12
- @rebuilt = [] # paths already rebuilt
13
15
  class << self
14
- attr_accessor :rebuild
16
+ attr_accessor :rebuild, :skip_warning
15
17
 
16
18
  # Check whether path requires rebuild and do it if required
17
19
  def check_rebuild(path)
@@ -25,38 +27,34 @@ class Rematch
25
27
 
26
28
  # Instantiated at each test, stores the path and the unique id of the test being run
27
29
  def initialize(path:, id:)
28
- path = "#{path}#{DEFAULT[:ext]}"
29
- self.class.check_rebuild(path)
30
- @store = YAML::Store.new(path, true)
30
+ store_path = "#{path}#{CONFIG[:ext]}"
31
+ self.class.check_rebuild(store_path)
32
+ @store = YAML::Store.new(store_path, true)
31
33
  @id = id.tr('#: ', '_') # easier key string for clumsy yaml parsers/highlighters
32
34
  end
33
35
 
34
36
  # Retrieve the stored value for the current assertion if its key is known; store the value otherwise
35
- def rematch(key, value)
37
+ def rematch(key, value, overwrite: nil)
36
38
  # key = assertion_key(key)
37
39
  @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
40
+ if s.root?(@id) # there is the root id
41
+ if s[@id].key?(key) && !overwrite # there is the key and not overwrite
42
+ s[@id][key] # return it
43
+ else # not such a key
44
+ s[@id][key] = value # set it
45
+ store_warning(key) unless overwrite
46
+ value
43
47
  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
48
+ else # there is no root yet
49
+ s[@id] = { key => value } # the key is the first one
50
+ store_warning(key)
51
+ value # always return the value
47
52
  end
48
53
  end
49
54
  end
50
55
 
51
- # Store the value
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
56
+ def store_warning(key)
57
+ warn "Rematch stored new value for: #{key.inspect}\n#{@id}\n#{@store.path}\n\n" \
58
+ unless Rematch.skip_warning
61
59
  end
62
60
  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: 3.0.0
4
+ version: 3.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: 2024-07-20 00:00:00.000000000 Z
11
+ date: 2024-07-21 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