rematch 1.3.1 → 1.4.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: 9f3271af42b8c0ebd9bd6c291e07fe71c1a90da689c211d170169b4ad25f6333
4
- data.tar.gz: 3a27075b4698939aa160c670e27a937bc7f958d4918257e5264057caf17dbf2e
3
+ metadata.gz: c2a78aaba52539be2d6d48d6c9ab22cb42619fb2caaae180b910c0479d80a7f2
4
+ data.tar.gz: c297708164e69b9af694ad7ed82e88a77566ab9dc84061cd0fef82507e2d942a
5
5
  SHA512:
6
- metadata.gz: 71ce7f05a928e044bca8d416df72a316a9d6f280d8fb05570e5b8f6a380568c378d8aedba8374f5a31e02069c262a1e92cf152f819702d5e8eebdb3f7445067e
7
- data.tar.gz: b12f5b0f28535c42457d6a4da0266472ef4968691a4d6969c919090849d9d14394f5ef117955b52b684b0292e08263812220b340acb0071781960536da8c7aca
6
+ metadata.gz: 5026206bb987112ecd2cb028d72bb3e128163d44f3e44537f1e745163325196656c5bf03bebac6ae74998c52f2be4b0e7dd3c7e4af575565c2bd6f9ebceff4dd
7
+ data.tar.gz: ff729f5a2aa8bb2e405ec8f4608cbfd07cc53f32440d1041be0fed6ff437cf37f1a5441cff2d8626d477e7be274942bd73f2db5044c846dcfa6fa07a5560a2ea
@@ -10,7 +10,7 @@ module Minitest
10
10
  end
11
11
  end
12
12
 
13
- # reopen the minitest class
13
+ # Reopen the minitest class
14
14
  class Test
15
15
  def before_setup
16
16
  super
@@ -18,18 +18,24 @@ module Minitest
18
18
  end
19
19
  end
20
20
 
21
- # reopen the minitest module
21
+ # Reopen the minitest module
22
22
  module Assertions
23
23
  def assert_rematch(actual, *args)
24
24
  assertion = :assert_equal
25
25
  message = nil
26
26
  args.each { |arg| arg.is_a?(Symbol) ? assertion = arg : message = arg }
27
- send assertion, @rematch.rematch(actual), actual, message
27
+ send assertion, @rematch.rematch(actual), actual, message # assert that the stored value is the same
28
+ end
29
+
30
+ def store_assert_rematch(actual, *_args)
31
+ @rematch.store(actual)
32
+ raise Minitest::Assertion, '[rematch] the value has been stored: remove the "store_" prefix to pass the test'
28
33
  end
29
34
  end
30
35
 
31
- # reopen the minitest module
36
+ # Reopen the minitest module
32
37
  module Expectations
33
38
  infect_an_assertion :assert_rematch, :must_rematch, true # dont_flip
39
+ infect_an_assertion :store_assert_rematch, :store_must_rematch, true # dont_flip
34
40
  end
35
41
  end
data/lib/rematch.rb CHANGED
@@ -5,7 +5,7 @@ require 'fileutils'
5
5
 
6
6
  # Implement the key/value store
7
7
  class Rematch
8
- VERSION = '1.3.1'
8
+ VERSION = '1.4.0'
9
9
  EXT = '.rematch'
10
10
 
11
11
  @rebuild = false
@@ -13,6 +13,7 @@ class Rematch
13
13
  class << self
14
14
  attr_accessor :rebuild
15
15
 
16
+ # Check whether path requires rebuild and do it if required
16
17
  def check_rebuild(path)
17
18
  return unless @rebuild && !@rebuilt.include?(path)
18
19
 
@@ -22,7 +23,7 @@ class Rematch
22
23
  end
23
24
  end
24
25
 
25
- # path and unique id of the test being run
26
+ # Path and unique id of the test being run
26
27
  def initialize(path:, id:)
27
28
  path = "#{path}#{EXT}"
28
29
  self.class.check_rebuild(path)
@@ -31,9 +32,19 @@ class Rematch
31
32
  @count = 0
32
33
  end
33
34
 
34
- # store if unknown; retrieve otherwise
35
+ # Retrieve the stored value if the key is known; store the value otherwise
35
36
  def rematch(value)
36
- key = "[#{@count += 1}] #{@id}"
37
+ key = count_key
37
38
  @store.transaction { |s| s.root?(key) ? s[key] : s[key] = value }
38
39
  end
40
+
41
+ def store(value)
42
+ @store.transaction { |s| s[count_key] = value }
43
+ end
44
+
45
+ private
46
+
47
+ def count_key
48
+ "[#{@count += 1}] #{@id}"
49
+ end
39
50
  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.3.1
4
+ version: 1.4.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-06-06 00:00:00.000000000 Z
11
+ date: 2021-12-08 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,8 @@ files:
25
25
  homepage: https://github.com/ddnexus/rematch
26
26
  licenses:
27
27
  - MIT
28
- metadata: {}
28
+ metadata:
29
+ rubygems_mfa_required: 'true'
29
30
  post_install_message:
30
31
  rdoc_options: []
31
32
  require_paths:
@@ -34,14 +35,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
34
35
  requirements:
35
36
  - - ">"
36
37
  - !ruby/object:Gem::Version
37
- version: '2.1'
38
+ version: '2.5'
38
39
  required_rubygems_version: !ruby/object:Gem::Requirement
39
40
  requirements:
40
41
  - - ">="
41
42
  - !ruby/object:Gem::Version
42
43
  version: '0'
43
44
  requirements: []
44
- rubygems_version: 3.2.15
45
+ rubygems_version: 3.2.32
45
46
  signing_key:
46
47
  specification_version: 4
47
48
  summary: Declutter your test files from large hardcoded data and update them automatically