test_changes 0.2.0 → 0.3.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
  SHA1:
3
- metadata.gz: 2df6a30cc05c9b8f553a8669986694b2572ca420
4
- data.tar.gz: 71c96602d2c338981e6afe322da2431165fb7ff6
3
+ metadata.gz: 8cc70f46a0ecc0eb63dbf411fdca42a39d0ec58d
4
+ data.tar.gz: c39900feb27bf873361bcb9d2cdbb9722751a0d1
5
5
  SHA512:
6
- metadata.gz: 0743c92860832fca6d404bbae31c5b0faedb52df44616190052652eb3c410eabadab8c19236be295cc1a03ae070cac040b9c1ccc7e43f0c0d1a861be7a86f942
7
- data.tar.gz: 701f39dd0669df793fc6d292f20cc88c2cfd161a12f10fbc0a0eea22a540727f0ca7a9a2051103538d90adc4c0ea567e3bbcf5086658507fbeb2d73c6503ec38
6
+ metadata.gz: 0e125f2b5f8126a7bb443b5adaacb4de1b99c46172210bfb2ae6cbd82a8dd0fdb2dddc6ad7798363106738f28aec89eada6b304e2de79b16fabdee8df6dffddb
7
+ data.tar.gz: ebb3652470a3a377e88b11f1cbd45dfc0f4295eb2875ab9676e1297735c2bcb94e5f85398ab86165490f4898260a738640afe23873becfe45d690ec6d90c8c6f
data/.test-changes.yml CHANGED
@@ -1,5 +1,9 @@
1
1
  rspec:
2
- ^lib/(.+)\.rb: spec/\1_spec.rb
3
- ^spec/(.+)_spec.rb: spec/\1_spec.rb
2
+ finding_patterns:
3
+ ^lib/(.+)\.rb: spec/\1_spec.rb
4
+ ^spec/(.+)_spec.rb: spec/\1_spec.rb
5
+ exclude:
6
+ - spec/fixtures/**/*
4
7
  rubocop:
5
- ^(.+)\.rb: \1.rb
8
+ finding_patterns:
9
+ ^(.+)\.rb: \1.rb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  ## master
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Breaking changes
6
+
7
+ * Reintroduced finding_patterns option in config file. See README for more info.
8
+
9
+ ### New features
10
+
11
+ * You can now list files that should be excluded when running a command.
12
+ * You can now specify glob patterns as substitution patterns.
13
+
3
14
  ## 0.2.0
4
15
 
5
16
  ### Breaking changes
data/README.md CHANGED
@@ -31,28 +31,36 @@ Add a `.test-changes.yml` configuration file to your repo. Example:
31
31
  ```yaml
32
32
  ---
33
33
  rspec:
34
- ^lib/(.+)\.rb: spec/\1_spec.rb
35
- ^spec/(.+)_spec.rb: spec/\1_spec.rb
34
+ finding_patterns:
35
+ ^lib/(.+)\.rb: spec/\1_spec.rb
36
+ ^spec/(.+)_spec.rb: spec/\1_spec.rb
37
+ exclude:
38
+ - spec/fixtures/**/*
36
39
  rubocop:
37
- ^(.+)\.rb: \1.rb
40
+ finding_patterns:
41
+ ^(.+)\.rb: \1.rb
38
42
  ```
39
43
 
40
- The options
44
+ At the root of the file, we have the commands for running the tests. Examples: `rspec`, `zeus rspec`, `rubocop`.
41
45
 
42
- * The keys - The commands for running the tests.
43
- Example: `rspec`, `zeus rspec`, `rubocop`.
46
+ These are the options under each command:
44
47
 
45
- * The values - The finding patterns. If the name of a changed file matches
48
+ * `finding_patterns` - If the name of a changed file matches
46
49
  the regular expression, `test_changes` will test the file's matching tests.
47
50
  Can accept an array of tests:
48
51
 
49
52
  ```yaml
50
53
  rspec:
51
- ^lib/test_changes\.rb:
52
- - spec/test_changes_spec.rb
53
- - spec/test_changes/client_spec.rb
54
+ finding_patterns:
55
+ ^lib/test_changes\.rb:
56
+ - spec/test_changes_spec.rb
57
+ - spec/test_changes/*_spec.rb
54
58
  ```
55
59
 
60
+ The values can also be glob patterns.
61
+
62
+ * `exclude` - Patterns of files that should be excluded from the run.
63
+
56
64
  ## Usage
57
65
 
58
66
  `test-changes -c [commit] -- [test_tool_arguments]`
@@ -68,7 +76,7 @@ Examples:
68
76
  ```
69
77
  test-changes
70
78
  test-changes -c master
71
- test-changes -c HEAD^ -- --format=documentation
79
+ test-changes -r rspec -c HEAD^ -- --format=documentation
72
80
  ```
73
81
 
74
82
  ## Known to work on
@@ -78,7 +86,7 @@ test-changes -c HEAD^ -- --format=documentation
78
86
 
79
87
  ## Development
80
88
 
81
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
89
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle console` for an interactive prompt that will allow you to experiment.
82
90
 
83
91
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
84
92
 
data/exe/test-changes CHANGED
@@ -2,16 +2,17 @@
2
2
 
3
3
  require 'test_changes/argv_wrapper'
4
4
  require 'test_changes/client'
5
+ require 'test_changes/config_setup_service'
5
6
  require 'test_changes/find_runner_service'
6
7
 
7
8
  argv_wrapper = TestChanges::ARGVWrapper.new(ARGV)
8
- runner = TestChanges::FindRunnerService.new(argv_wrapper).call
9
+ config = TestChanges::ConfigSetupService.call
10
+
11
+ find_runner_service =
12
+ TestChanges::FindRunnerService.new(argv_wrapper: argv_wrapper, config: config)
9
13
 
10
14
  client = TestChanges::Client.new(
11
- runner_name: runner.name,
12
- finding_patterns: runner.finding_patterns,
13
- commit: argv_wrapper.commit,
14
- runner_call_options: argv_wrapper.runner_call_options,
15
- verbose: argv_wrapper.verbose?)
15
+ argv_wrapper: argv_wrapper,
16
+ runner: find_runner_service.call)
16
17
 
17
18
  client.call
@@ -3,39 +3,36 @@ require 'test_changes/finding_pattern'
3
3
  module TestChanges
4
4
  class Client
5
5
  def initialize(options)
6
- @runner_name = options[:runner_name]
7
- @finding_patterns = options[:finding_patterns]
8
- @commit = options[:commit]
9
- @runner_call_options = options[:runner_call_options]
10
- @verbose = options[:verbose]
6
+ @argv_wrapper = options[:argv_wrapper]
7
+ @runner = options[:runner]
11
8
  end
12
9
 
13
10
  # rubocop:disable Metrics/AbcSize
14
11
  def call
15
- log "paths_changed_since_commit #{commit}:",
12
+ log "Paths changed since commit #{argv_wrapper.commit}:",
16
13
  paths_changed_since_commit.inspect
17
14
 
18
- log "matches:", matches.inspect
15
+ log "Matches:", matches.inspect
19
16
 
20
- log "existing_matches:", existing_matches.inspect
17
+ log "Existing matches:", existing_matches.inspect
21
18
 
22
19
  return if existing_matches.empty?
23
20
 
24
- log "test_tool_call:", test_tool_call
21
+ log "Non-excluded matches:", included_matches.inspect
22
+
23
+ return if included_matches.empty?
24
+
25
+ log "Test tool call:", test_tool_call
25
26
  system(test_tool_call)
26
27
  end
27
28
  # rubocop:enable Metrics/AbcSize
28
29
 
29
30
  private
30
31
 
31
- attr_reader :commit,
32
- :finding_patterns,
33
- :runner_name,
34
- :runner_call_options,
35
- :verbose
32
+ attr_reader :argv_wrapper, :runner
36
33
 
37
34
  def log(header, message)
38
- return unless verbose?
35
+ return unless argv_wrapper.verbose?
39
36
 
40
37
  puts "\n#{header}"
41
38
  puts message
@@ -47,17 +44,21 @@ module TestChanges
47
44
 
48
45
  def paths_changed_since_commit
49
46
  @paths_changed_since_commit ||=
50
- `git diff --name-only --diff-filter=AMR #{commit}`.split("\n")
47
+ `git diff --name-only --diff-filter=AMR #{argv_wrapper.commit}`.split("\n")
51
48
  end
52
49
 
53
50
  def test_tool_call
54
51
  @test_tool_call ||= [
55
- runner_name,
56
- runner_call_options,
57
- existing_matches
52
+ runner.name,
53
+ argv_wrapper.runner_call_options,
54
+ included_matches
58
55
  ].flatten.compact.join(' ')
59
56
  end
60
57
 
58
+ def included_matches
59
+ runner.ignore_excluded_files_service.call(existing_matches)
60
+ end
61
+
61
62
  def existing_matches
62
63
  @existing_matches ||= matches.select { |match| File.exist?(match) }
63
64
  end
@@ -68,7 +69,7 @@ module TestChanges
68
69
  paths = paths_changed_since_commit
69
70
 
70
71
  @matches =
71
- paths.product(finding_patterns).map do |path, finding_pattern|
72
+ paths.product(runner.finding_patterns).map do |path, finding_pattern|
72
73
  finding_pattern.matching_paths(path)
73
74
  end
74
75
 
@@ -1,4 +1,5 @@
1
1
  require 'test_changes/finding_pattern'
2
+ require 'test_changes/runner'
2
3
  require 'yaml'
3
4
 
4
5
  module TestChanges
@@ -12,10 +13,13 @@ module TestChanges
12
13
  end
13
14
 
14
15
  def runners
15
- config.map do |runner_name, finding_pattern_maps|
16
+ config.map do |runner_name, options|
17
+ finding_pattern_maps = options['finding_patterns']
18
+
16
19
  Runner.new(
17
20
  name: runner_name,
18
- finding_patterns: FindingPattern.build(finding_pattern_maps))
21
+ finding_patterns: FindingPattern.build(finding_pattern_maps),
22
+ exclusion_patterns: options['exclude'])
19
23
  end
20
24
  end
21
25
 
@@ -1,11 +1,10 @@
1
- require 'test_changes/config_setup_service'
2
1
  require 'test_changes/runner'
3
2
 
4
3
  module TestChanges
5
4
  class FindRunnerService
6
- def initialize(argv_wrapper)
7
- @config = ConfigSetupService.call
5
+ def initialize(argv_wrapper: nil, config: nil)
8
6
  @argv_wrapper = argv_wrapper
7
+ @config = config
9
8
  end
10
9
 
11
10
  def call
@@ -8,11 +8,14 @@ module TestChanges
8
8
  end
9
9
 
10
10
  def matching_paths(path)
11
- results = substitution_patterns.map do |substitution_pattern|
12
- path.sub(matching_pattern, substitution_pattern) if matches?(path)
11
+ results = substitution_patterns.flat_map do |substitution_pattern|
12
+ if matches?(path)
13
+ substituted_pattern = path.sub(matching_pattern, substitution_pattern)
14
+ Pathname.glob(substituted_pattern)
15
+ end
13
16
  end
14
17
 
15
- results.compact
18
+ results.compact.map(&:to_s)
16
19
  end
17
20
 
18
21
  def self.build(patterns)
@@ -0,0 +1,17 @@
1
+ module TestChanges
2
+ class IgnoreExcludedFilesService
3
+ attr_reader :exclusion_patterns
4
+
5
+ def initialize(exclusion_patterns = [])
6
+ @exclusion_patterns = exclusion_patterns
7
+ end
8
+
9
+ def call(paths)
10
+ matching_paths = exclusion_patterns.flat_map do |pattern|
11
+ Pathname.glob(pattern)
12
+ end
13
+
14
+ paths - matching_paths.map(&:to_s)
15
+ end
16
+ end
17
+ end
@@ -1,13 +1,25 @@
1
+ require 'test_changes/ignore_excluded_files_service'
1
2
  require 'test_changes/config_setup_service'
2
3
 
3
4
  module TestChanges
4
5
  class Runner
5
- def initialize(name: nil, finding_patterns: nil, project_type_name: nil)
6
+ def initialize(
7
+ name: nil,
8
+ finding_patterns: nil,
9
+ exclusion_patterns: [],
10
+ project_type_name: nil)
11
+
6
12
  @name = name
7
13
  @finding_patterns = finding_patterns
14
+ @exclusion_patterns = exclusion_patterns
8
15
  @project_type_name = project_type_name
9
16
  end
10
17
 
11
- attr_reader :name, :finding_patterns, :project_type_name
18
+ def ignore_excluded_files_service
19
+ @ignore_excluded_files_service ||=
20
+ IgnoreExcludedFilesService.new(exclusion_patterns)
21
+ end
22
+
23
+ attr_reader :exclusion_patterns, :name, :finding_patterns, :project_type_name
12
24
  end
13
25
  end
@@ -1,3 +1,3 @@
1
1
  module TestChanges
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_changes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Mendoza
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
11
+ date: 2015-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.4.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.4.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.10.1
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.10.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Run only the tests affected by files changed since a given commit.
@@ -88,12 +88,12 @@ executables:
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - ".gitignore"
92
- - ".overcommit.yml"
93
- - ".rspec"
94
- - ".rubocop.yml"
95
- - ".test-changes.yml"
96
- - ".travis.yml"
91
+ - .gitignore
92
+ - .overcommit.yml
93
+ - .rspec
94
+ - .rubocop.yml
95
+ - .test-changes.yml
96
+ - .travis.yml
97
97
  - CHANGELOG.md
98
98
  - CODE_OF_CONDUCT.md
99
99
  - Gemfile
@@ -111,6 +111,7 @@ files:
111
111
  - lib/test_changes/error.rb
112
112
  - lib/test_changes/find_runner_service.rb
113
113
  - lib/test_changes/finding_pattern.rb
114
+ - lib/test_changes/ignore_excluded_files_service.rb
114
115
  - lib/test_changes/inferred_config.rb
115
116
  - lib/test_changes/runner.rb
116
117
  - lib/test_changes/version.rb
@@ -125,12 +126,12 @@ require_paths:
125
126
  - lib
126
127
  required_ruby_version: !ruby/object:Gem::Requirement
127
128
  requirements:
128
- - - ">="
129
+ - - '>='
129
130
  - !ruby/object:Gem::Version
130
131
  version: '0'
131
132
  required_rubygems_version: !ruby/object:Gem::Requirement
132
133
  requirements:
133
- - - ">="
134
+ - - '>='
134
135
  - !ruby/object:Gem::Version
135
136
  version: '0'
136
137
  requirements: []