rematch 0.0.1 → 1.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '049981ef362bab9fa4ec53dc1794bdb7e083f670991a57c51cbbd16b82fb1a24'
4
- data.tar.gz: 01b2c7c801cf8134ea6da3b9e99f0534e045bae129e52086a3f5f3315302bea5
3
+ metadata.gz: 9f3271af42b8c0ebd9bd6c291e07fe71c1a90da689c211d170169b4ad25f6333
4
+ data.tar.gz: 3a27075b4698939aa160c670e27a937bc7f958d4918257e5264057caf17dbf2e
5
5
  SHA512:
6
- metadata.gz: 68a13f561594b0c79bc10bfb27e339900f0c517ff364111456c6de0820ceed3b178da87c240195306e98b2558d142ace04a3857705a7b64e23623aa4830f6375
7
- data.tar.gz: 78baa00c6a04c6b39e2005f71743e8136b019b45851d9aa4a8221722f8f2e5679f92a5ba24c2f206661a51762d4905edcb08a6951c8c4a47add2f7e0803cebc9
6
+ metadata.gz: 71ce7f05a928e044bca8d416df72a316a9d6f280d8fb05570e5b8f6a380568c378d8aedba8374f5a31e02069c262a1e92cf152f819702d5e8eebdb3f7445067e
7
+ data.tar.gz: b12f5b0f28535c42457d6a4da0266472ef4968691a4d6969c919090849d9d14394f5ef117955b52b684b0292e08263812220b340acb0071781960536da8c7aca
@@ -4,18 +4,32 @@ require 'rematch'
4
4
 
5
5
  # Implement the minitest plugin
6
6
  module Minitest
7
+ def self.plugin_rematch_options(opts, _options)
8
+ opts.on '--rematch-rebuild', 'Rebuild the stores with the current entries/values' do
9
+ Rematch.rebuild = true
10
+ end
11
+ end
12
+
13
+ # reopen the minitest class
7
14
  class Test
8
15
  def before_setup
9
- @rematch = Rematch.new(path: method(name).source_location.first, id: location)
10
16
  super
17
+ @rematch = Rematch.new(path: method(name).source_location.first, id: location)
11
18
  end
12
19
  end
20
+
21
+ # reopen the minitest module
13
22
  module Assertions
14
- def assert_rematch(_expected, actual)
15
- assert_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
16
28
  end
17
29
  end
30
+
31
+ # reopen the minitest module
18
32
  module Expectations
19
- infect_an_assertion :assert_rematch, :must_rematch
33
+ infect_an_assertion :assert_rematch, :must_rematch, true # dont_flip
20
34
  end
21
35
  end
data/lib/rematch.rb CHANGED
@@ -1,16 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'yaml/store'
4
- require 'rematch/tasks'
4
+ require 'fileutils'
5
5
 
6
6
  # Implement the key/value store
7
7
  class Rematch
8
- VERSION = '0.0.1'
8
+ VERSION = '1.3.1'
9
9
  EXT = '.rematch'
10
10
 
11
+ @rebuild = false
12
+ @rebuilt = []
13
+ class << self
14
+ attr_accessor :rebuild
15
+
16
+ def check_rebuild(path)
17
+ return unless @rebuild && !@rebuilt.include?(path)
18
+
19
+ FileUtils.rm_f(path)
20
+ @rebuilt << path
21
+ puts "Rebuilt #{path}"
22
+ end
23
+ end
24
+
11
25
  # path and unique id of the test being run
12
26
  def initialize(path:, id:)
13
- @store = YAML::Store.new("#{path}#{EXT}", true)
27
+ path = "#{path}#{EXT}"
28
+ self.class.check_rebuild(path)
29
+ @store = YAML::Store.new(path, true)
14
30
  @id = id
15
31
  @count = 0
16
32
  end
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rematch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.3.1
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-17 00:00:00.000000000 Z
11
+ date: 2021-06-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: With rematch you can completely declutter your test files from hardcoded
14
- expected data and update them automatically in a few seconds instead of hours when
15
- your code changes
13
+ description: Instead of copying and pasting large outputs or big ruby structures into
14
+ all the affected test files every time your code change, you can do it the easy
15
+ way, possibly saving many hours of boring maintenance work!
16
16
  email:
17
17
  - dd.nexus@gmail.com
18
18
  executables: []
@@ -22,7 +22,6 @@ files:
22
22
  - LICENSE.txt
23
23
  - lib/minitest/rematch_plugin.rb
24
24
  - lib/rematch.rb
25
- - lib/rematch/tasks.rb
26
25
  homepage: https://github.com/ddnexus/rematch
27
26
  licenses:
28
27
  - MIT
@@ -35,7 +34,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
35
34
  requirements:
36
35
  - - ">"
37
36
  - !ruby/object:Gem::Version
38
- version: '2.5'
37
+ version: '2.1'
39
38
  required_rubygems_version: !ruby/object:Gem::Requirement
40
39
  requirements:
41
40
  - - ">="
@@ -45,5 +44,6 @@ requirements: []
45
44
  rubygems_version: 3.2.15
46
45
  signing_key:
47
46
  specification_version: 4
48
- summary: Rematch expected values with automatically stored values in tests
47
+ summary: Declutter your test files from large hardcoded data and update them automatically
48
+ when your code changes
49
49
  test_files: []
data/lib/rematch/tasks.rb DELETED
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rake'
4
-
5
- class Rematch
6
- module Tasks
7
- extend Rake::DSL
8
- namespace :rematch do
9
- desc 'Delete all the rematch stores below the tree=/path/to/test/dir (or current tree if omitted)'
10
- task :reset do
11
- pattern = Pathname.new(ENV['tree'] || '').join('**','*.rematch')
12
- Dir.glob(pattern).each { |f| File.delete(f) }
13
- end
14
- end
15
- end
16
- end