rematch 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '049981ef362bab9fa4ec53dc1794bdb7e083f670991a57c51cbbd16b82fb1a24'
4
+ data.tar.gz: 01b2c7c801cf8134ea6da3b9e99f0534e045bae129e52086a3f5f3315302bea5
5
+ SHA512:
6
+ metadata.gz: 68a13f561594b0c79bc10bfb27e339900f0c517ff364111456c6de0820ceed3b178da87c240195306e98b2558d142ace04a3857705a7b64e23623aa4830f6375
7
+ data.tar.gz: 78baa00c6a04c6b39e2005f71743e8136b019b45851d9aa4a8221722f8f2e5679f92a5ba24c2f206661a51762d4905edcb08a6951c8c4a47add2f7e0803cebc9
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Domizio Demichelis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rematch'
4
+
5
+ # Implement the minitest plugin
6
+ module Minitest
7
+ class Test
8
+ def before_setup
9
+ @rematch = Rematch.new(path: method(name).source_location.first, id: location)
10
+ super
11
+ end
12
+ end
13
+ module Assertions
14
+ def assert_rematch(_expected, actual)
15
+ assert_equal(@rematch.rematch(actual), actual)
16
+ end
17
+ end
18
+ module Expectations
19
+ infect_an_assertion :assert_rematch, :must_rematch
20
+ end
21
+ end
data/lib/rematch.rb ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml/store'
4
+ require 'rematch/tasks'
5
+
6
+ # Implement the key/value store
7
+ class Rematch
8
+ VERSION = '0.0.1'
9
+ EXT = '.rematch'
10
+
11
+ # path and unique id of the test being run
12
+ def initialize(path:, id:)
13
+ @store = YAML::Store.new("#{path}#{EXT}", true)
14
+ @id = id
15
+ @count = 0
16
+ end
17
+
18
+ # store if unknown; retrieve otherwise
19
+ def rematch(value)
20
+ key = "[#{@count += 1}] #{@id}"
21
+ @store.transaction { |s| s.root?(key) ? s[key] : s[key] = value }
22
+ end
23
+ end
@@ -0,0 +1,16 @@
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
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rematch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Domizio Demichelis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-05-17 00:00:00.000000000 Z
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
16
+ email:
17
+ - dd.nexus@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - LICENSE.txt
23
+ - lib/minitest/rematch_plugin.rb
24
+ - lib/rematch.rb
25
+ - lib/rematch/tasks.rb
26
+ homepage: https://github.com/ddnexus/rematch
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">"
37
+ - !ruby/object:Gem::Version
38
+ version: '2.5'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubygems_version: 3.2.15
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Rematch expected values with automatically stored values in tests
49
+ test_files: []