rematch 1.1.0 → 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: 436705eae5a3606fde733d091c5af71bb539da4187080c7527dca36a440c1684
4
- data.tar.gz: 5543594f5f10f4c3021cd9a5947a938c4e3b04b34f3ce0086dcde4da6698ef46
3
+ metadata.gz: c2a78aaba52539be2d6d48d6c9ab22cb42619fb2caaae180b910c0479d80a7f2
4
+ data.tar.gz: c297708164e69b9af694ad7ed82e88a77566ab9dc84061cd0fef82507e2d942a
5
5
  SHA512:
6
- metadata.gz: 34b831ff01adca363cbc924ededdebd6f801ea87f5d71e9fd1ca259f6c40d92bfd3eed39ceed3153b72aaaa352964e2f2337ae17111e896c33716f969c413d34
7
- data.tar.gz: 1dd5425ccc6be7505956f06680aa7f8e5be90acdc0822a79fb8477a4142dc3afb101b8bf8c74d508065c08865ba9ff5d5df9826cd8a171a777cd8e6a49bbf9e5
6
+ metadata.gz: 5026206bb987112ecd2cb028d72bb3e128163d44f3e44537f1e745163325196656c5bf03bebac6ae74998c52f2be4b0e7dd3c7e4af575565c2bd6f9ebceff4dd
7
+ data.tar.gz: ff729f5a2aa8bb2e405ec8f4608cbfd07cc53f32440d1041be0fed6ff437cf37f1a5441cff2d8626d477e7be274942bd73f2db5044c846dcfa6fa07a5560a2ea
@@ -9,18 +9,33 @@ module Minitest
9
9
  Rematch.rebuild = true
10
10
  end
11
11
  end
12
+
13
+ # Reopen the minitest class
12
14
  class Test
13
15
  def before_setup
14
16
  super
15
17
  @rematch = Rematch.new(path: method(name).source_location.first, id: location)
16
18
  end
17
19
  end
20
+
21
+ # Reopen the minitest module
18
22
  module Assertions
19
- def assert_rematch(equality, actual)
20
- send :"assert_#{equality||:equal}", @rematch.rematch(actual), actual
23
+ def assert_rematch(actual, *args)
24
+ assertion = :assert_equal
25
+ message = nil
26
+ 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
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'
21
33
  end
22
34
  end
35
+
36
+ # Reopen the minitest module
23
37
  module Expectations
24
- infect_an_assertion :assert_rematch, :must_rematch
38
+ infect_an_assertion :assert_rematch, :must_rematch, true # dont_flip
39
+ infect_an_assertion :store_assert_rematch, :store_must_rematch, true # dont_flip
25
40
  end
26
41
  end
data/lib/rematch.rb CHANGED
@@ -5,21 +5,25 @@ require 'fileutils'
5
5
 
6
6
  # Implement the key/value store
7
7
  class Rematch
8
- VERSION = '1.1.0'
8
+ VERSION = '1.4.0'
9
9
  EXT = '.rematch'
10
10
 
11
+ @rebuild = false
11
12
  @rebuilt = []
12
13
  class << self
13
14
  attr_accessor :rebuild
15
+
16
+ # Check whether path requires rebuild and do it if required
14
17
  def check_rebuild(path)
15
18
  return unless @rebuild && !@rebuilt.include?(path)
19
+
16
20
  FileUtils.rm_f(path)
17
21
  @rebuilt << path
18
22
  puts "Rebuilt #{path}"
19
23
  end
20
24
  end
21
25
 
22
- # path and unique id of the test being run
26
+ # Path and unique id of the test being run
23
27
  def initialize(path:, id:)
24
28
  path = "#{path}#{EXT}"
25
29
  self.class.check_rebuild(path)
@@ -28,9 +32,19 @@ class Rematch
28
32
  @count = 0
29
33
  end
30
34
 
31
- # store if unknown; retrieve otherwise
35
+ # Retrieve the stored value if the key is known; store the value otherwise
32
36
  def rematch(value)
33
- key = "[#{@count += 1}] #{@id}"
37
+ key = count_key
34
38
  @store.transaction { |s| s.root?(key) ? s[key] : s[key] = value }
35
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
36
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.1.0
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-05-20 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