test-map 0.1.0 → 0.2.0

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: 0a6119ac2cd9cbbed7ab386e84db91d4af55abb17839e4eaed8e2db66aed8f10
4
- data.tar.gz: 454388e46781b590ecc38d8b5bab9d6395f8b5db48c8b7f1241533fc519995c4
3
+ metadata.gz: cff4303356d351f21830fabfa15aa8c83074739a7df7b8eb3c05765b6c2a9a18
4
+ data.tar.gz: 86c24f5558da531e9aa4cfec819ca21b9a9a7328113b5925509a72b128ffcc3e
5
5
  SHA512:
6
- metadata.gz: 8165ebf293a69de809d2c04cb496836d44b722ae52870bd13cb15688493066e65c7d9daa422bd62a86fd87cec871bfbe7acfec9ffdea26b44091e6d84b2d8936
7
- data.tar.gz: 62f784cfb4a6968c8ccd481477cef3e4d5eec0dbcaa04bfec295514ea8b5ae1bc667c8f99d46d6aabf4c888bec3d23a4fce00a2bbbddd5b8cc6396a381121f68
6
+ metadata.gz: 0ae009024978af278f98b2fc51c9abcb4907e0d14e575f179fd0edc2247356bcc07f3349b80dae599b8f8932d4e1b9534fab17e51e555d7d1d3e19fa6a00219e
7
+ data.tar.gz: 06ffd99ddcc28a9025d6a998a19766c9aa378489a6cb39e92a2f0b401da794fc05a4a9d17c2eb60b5456936088a87e12ce65bceeb4db1353230a62d0a00bbdb3
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file.
6
6
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
7
7
  and this project adheres to [Semantic Versioning](http://semver.org/).
8
8
 
9
- ## [Unreleased] - yyyy-mm-dd
9
+ ## 0.2.0 - 2024-10-25
10
+
11
+ Provide explicit Test Task via Rake for Minitest, Rspec, and Rails. Extend
12
+ documentation.
13
+
14
+ ## 0.1.0 - 2024-09-22
10
15
 
11
16
  Initial release.
data/README.md CHANGED
@@ -19,20 +19,6 @@ Add test-map to your Gemfile.
19
19
  $ bundle add test-map
20
20
  ```
21
21
 
22
- On demand you can adapt the configuration to your needs.
23
-
24
- ```ruby
25
- TestMap::Configure.configure do |config|
26
- config.logger = Logger.new($stdout) # default logs to dev/null
27
- config.out_file = 'my-test-map.yml' # default is .test-map.yml
28
- # defaults to [%r{^(vendor|test|spec)/}] }
29
- config.exclude_patterns = [%r{^(libraries|testsuite)/}]
30
- # register a custom rule to match new files; must implement `call(file)`;
31
- # defaults to nil
32
- config.natural_mapping = ->(file) { file.sub(%r{^library/}, 'test/') }
33
- end
34
- ```
35
-
36
22
  ### Minitest
37
23
 
38
24
  Include test-map in your test helper. Typically you want to include it
@@ -53,6 +39,25 @@ $ TEST_MAP=1 bundle exec ruby -Itest test/models/user_test.rb
53
39
  $ TEST_MAP=1 bundle exec rake test
54
40
  ```
55
41
 
42
+ Using the a dedicated rake task you can connect a file watcher and trigger
43
+ tests on file changes.
44
+
45
+ ```ruby
46
+ # filename: Rakefile
47
+ require 'test_map/test_task'
48
+
49
+ TestMap::TestTask.create
50
+ ```
51
+
52
+ Using [entr](https://eradman.com/entrproject/) as example file watcher.
53
+
54
+ ```sh
55
+ # find all ruby files | watch them, postpone first execution, clear screen
56
+ # with every run and on file change run test suite for the changed file
57
+ # (placeholder /_).
58
+ $ find . -name "*.rb" | entr -cp bundle exec rake test:changes /_
59
+ ```
60
+
56
61
  ### Rspec
57
62
 
58
63
  Include test-map in your test helper. Typically you want to include it
@@ -69,8 +74,32 @@ Run your tests with the `TEST_MAP` environment variable set.
69
74
  $ TEST_MAP=1 bundle exec rspec
70
75
  ```
71
76
 
77
+ ## Configuration
78
+
79
+ On demand you can adapt the configuration to your needs.
80
+
81
+ ```ruby
82
+ TestMap::Configure.configure do |config|
83
+ config.logger = Logger.new($stdout) # default logs to dev/null
84
+ config.out_file = 'my-test-map.yml' # default is .test-map.yml
85
+ # defaults to [%r{^(vendor)/}] }
86
+ config.exclude_patterns = [%r{^(vendor|other_libraries)/}]
87
+ # register a custom rule to match new files; must implement `call(file)`;
88
+ # defaults to nil
89
+ config.natural_mapping = ->(file) { file.sub(%r{^library/}, 'test/') }
90
+ end
91
+ ```
92
+
72
93
  ## Development
73
94
 
95
+ Open list of features:
96
+
97
+ - [ ] Configure file exclude list (e.g. test files are not needed).
98
+ - [ ] Auto-handle packs, packs with subdirectories.
99
+ - [ ] Demonstrate usage with file watchers.
100
+ - [ ] Demonstrate CI pipelines with GitHub actions and GitLab CI.
101
+ - [ ] Merge results.
102
+
74
103
  ```sh
75
104
  $ bundle install # install dependencies
76
105
  $ bundle exec rake # run testsuite
@@ -79,5 +108,5 @@ $ bundle exec rubocop # run linter
79
108
 
80
109
  ## Contributing
81
110
 
82
- Bug reports and pull requests are welcome on
111
+ Bug reports and pull requests are very welcome on
83
112
  [GitHub](https://github.com/unused/test-map).
@@ -11,7 +11,8 @@ module TestMap
11
11
 
12
12
  def self.default_config
13
13
  { logger: Logger.new('/dev/null'), out_file: '.test-map.yml',
14
- exclude_patterns: [%r{^(vendor)/}], natural_mapping: nil }
14
+ exclude_patterns: [%r{^(vendor)/}], natural_mapping: nil,
15
+ skip_files: [%r{^(test/)}], merge: false }
15
16
  end
16
17
  end
17
18
  end
@@ -5,13 +5,19 @@ module TestMap
5
5
  class FileRecorder
6
6
  def initialize = @files = []
7
7
 
8
- def trace
8
+ def trace(&block)
9
9
  raise TraceInUseError.default if @trace&.enabled?
10
10
 
11
11
  @trace = TracePoint.new(:call) do |tp|
12
12
  TestMap.logger.debug "#{tp.path}:#{tp.lineno}"
13
13
  @files << tp.path
14
- end.tap(&:enable)
14
+ end
15
+
16
+ if block_given?
17
+ @trace.enable { block.call }
18
+ else
19
+ @trace.enable
20
+ end
15
21
  end
16
22
 
17
23
  def stop = @trace&.disable
@@ -5,10 +5,8 @@ TestMap.logger.info 'Loading RSpec plugin'
5
5
  RSpec.configure do |config|
6
6
  config.around(:example) do |example|
7
7
  # path = example.metadata[:example_group][:file_path]
8
- recorder = TestMap::FileRecorder.new.tap(&:trace)
9
- example.run
10
- ensure
11
- recorder.stop
8
+ recorder = TestMap::FileRecorder.new
9
+ recorder.trace { example.run }
12
10
  TestMap.reporter.add recorder.results
13
11
  end
14
12
 
@@ -15,6 +15,12 @@ module TestMap
15
15
  end
16
16
  end
17
17
 
18
+ def write(file)
19
+ result = to_yaml
20
+ result = YAML.safe_load_file(file).deep_merge(result) if Config.config[:merge]
21
+ File.write file, result
22
+ end
23
+
18
24
  def results = @results.transform_values { _1.to_a.sort }.sort.to_h
19
25
  def to_yaml = results.to_yaml
20
26
  end
@@ -15,6 +15,13 @@ module TestMap
15
15
  @name = name
16
16
  end
17
17
 
18
+ # Adapter for rspec test task
19
+ class RailsTestTask
20
+ attr_accessor :files
21
+
22
+ def call = Rails::TestUnit::Runner.run_from_rake('test', files)
23
+ end
24
+
18
25
  # Adapter for minitest test task.
19
26
  class MinitestTask < Minitest::TestTask
20
27
  def call = ruby(make_test_cmd, verbose: false)
@@ -38,7 +45,8 @@ module TestMap
38
45
  desc 'Run tests for changed files'
39
46
  task :changes do
40
47
  out_file = "#{Dir.pwd}/.test-map.yml"
41
- test_files = Mapping.new(out_file).lookup(*ARGV[1..])
48
+ args = defined?(Rails) ? ENV['TEST']&.split : ARGV[1..]
49
+ test_files = Mapping.new(out_file).lookup(*args)
42
50
 
43
51
  # puts "Running tests #{test_files.join(' ')}"
44
52
  test_task.files = test_files
@@ -50,7 +58,10 @@ module TestMap
50
58
  def test_task = @test_task ||= build_test_task
51
59
 
52
60
  def build_test_task
53
- if defined?(Minitest)
61
+ if defined?(Rails)
62
+ return RailsTestTask.new
63
+ elsif defined?(Minitest)
64
+ require 'minitest/test_task'
54
65
  return MinitestTask.new
55
66
  elsif defined?(RSpec)
56
67
  return RSpecTask.new
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TestMap
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-map
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Lipautz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-22 00:00:00.000000000 Z
11
+ date: 2024-10-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Track files that are covered by test files to execute only the necessary