test_diff 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDViODIxNjRmYWI0NmYzZjVhYTdhNzA5MzBkYzQ0YjJjMzg0NDAyYw==
4
+ MWVkMDZlMTVhZWIwMDYzMjk1ZTM1MTc4N2ZlMDQwZjFlZWM4Mzc3Nw==
5
5
  data.tar.gz: !binary |-
6
- YjI4MmM3YzBhMzdmZTU5MjgxMDdjYjFiMWNkM2Q4N2MyMWE5MWE5MQ==
6
+ ZTAzOGEwOTNkNTRjZGYwM2Q4YTZhODdjN2I4ZGQ1Y2QyZDJkZThkOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Mzc3ZWVjYzZkN2JkZmVjYjllMTkxNjcwNGIyZGZmYWJkZTE4MDQ3ZjRiNGQw
10
- NjlmYTIwODdiZGI0NTVlMGM4ZThjODBjOTQzNWZiZGVmODk3OWY4YmZhYjJi
11
- ZGViMDQwNDU3N2IyZjZmMTQxMGNlNDI1NjNkODhjN2UzMjlmMjI=
9
+ ZTEyNzk0OTBkZjRkNGIxM2ExOTM2YzRlZmZlZDZlY2NmZmIzNzIyOTFlZmEw
10
+ ODUxZTdjYzhlOGJjZGQ2ZDNmZWE3Y2VmNjI5ZjViZmExZWQ1OTM1OGQ5YjI4
11
+ OTljNjRmZWVkN2FjYTVlMWEzZGNjNjcyODlkODMyZGE4MjNjMGY=
12
12
  data.tar.gz: !binary |-
13
- OTk5MTA1MjUzNGVmN2RkMGEyYTI0OGFmYjMwMWQ4NzBkMzM0ZGNiYWFlNTZk
14
- ZTVjYTE0YzA1NjQ0NzY4NzMwMWQxODk3NTA2ZjdlMjdlZDQxNjk3YTdmYTQy
15
- OTFjNzZlMjczMTcxMWQ4MTBlN2I5NjNiNTYxM2MwMDI1ZjVmMGI=
13
+ NGFhYzA4MjU2MmZkZjAyZGFlYWUwZDNlYTY0YmRhNjMwNzExNGRjZmU0Y2M3
14
+ NTlmOWE1MzMyYjM3NjM0OGZiNTQ0NWEyMzg2NDRhNTdiMDFmOGJiMzRlN2I4
15
+ NWMxZmNiNjI4MzgyOTg3OWY4NGU5ZDU3MzBlMjMwZDdjN2VkYWQ=
@@ -15,6 +15,7 @@ module TestDiff
15
15
 
16
16
  def run
17
17
  add_changed_files
18
+ remove_tests_that_do_not_exist
18
19
  remove_tests_in_wrong_folder
19
20
  select_test_group
20
21
  run_test_group
@@ -37,6 +38,12 @@ module TestDiff
37
38
  @specs_to_run = @specs_to_run.slice(group.to_i * groups_size, groups_size)
38
39
  end
39
40
 
41
+ def remove_tests_that_do_not_exist
42
+ @specs_to_run.delete_if do |s|
43
+ !File.exist?(s)
44
+ end
45
+ end
46
+
40
47
  def remove_tests_in_wrong_folder
41
48
  @specs_to_run.delete_if do |s|
42
49
  !s.start_with?("#{spec_folder}/")
@@ -44,22 +51,28 @@ module TestDiff
44
51
  end
45
52
 
46
53
  def add_changed_files
47
- cmd = "git diff --name-only #{sha1} HEAD"
48
- `#{cmd}`.split("\n").each do |file_name|
54
+ _build_specs_to_run
55
+
56
+ @specs_to_run.flatten!
57
+ @specs_to_run.sort!
58
+ @specs_to_run.uniq!
59
+ end
60
+
61
+ def _build_specs_to_run
62
+ files = []
63
+ `git diff --name-only #{sha1} HEAD`.split("\n").each do |file_name|
49
64
  if file_name.end_with?('spec.rb') || file_name.end_with?('test.rb')
50
65
  @specs_to_run << file_name
51
66
  elsif !file_name.start_with?(@storage.folder)
52
- _add_calculated_tests(file_name)
67
+ files << file_name
53
68
  _add_rails_view_spec(file_name)
54
69
  end
55
70
  end
56
-
57
- @specs_to_run.flatten!
58
- @specs_to_run.sort!
71
+ _add_calculated_tests(files)
59
72
  end
60
73
 
61
- def _add_calculated_tests(file_name)
62
- @specs_to_run << @storage.find_for(file_name)
74
+ def _add_calculated_tests(files)
75
+ @specs_to_run << @storage.find_for(files, spec_folder)
63
76
  end
64
77
 
65
78
  def _add_rails_view_spec(file_name)
@@ -31,10 +31,12 @@ module TestDiff
31
31
  end
32
32
  end
33
33
 
34
- def find_for(file)
34
+ def find_for(files, sub_folder = nil)
35
35
  results = []
36
- Dir["#{@folder}/**/*.yml"].each do |storage_file|
37
- find_for_storage_file(results, storage_file, file)
36
+ root_folder = @folder
37
+ root_folder += "/#{sub_folder}" if sub_folder
38
+ Dir["#{root_folder}/**/*.yml"].each do |storage_file|
39
+ find_for_storage_file(results, storage_file, files)
38
40
  end
39
41
  results
40
42
  end
@@ -47,14 +49,21 @@ module TestDiff
47
49
 
48
50
  private
49
51
 
50
- def find_for_storage_file(results, storage_file, file)
52
+ def find_for_storage_file(results, storage_file, files)
51
53
  YAML::Store.new(storage_file).transaction(true) do |store|
52
- unless store[file].to_s.split(',').delete_if { |s| s == '' || s == '0' }.empty?
53
- results << storage_file.gsub('.yml', '').gsub("#{@folder}/", '')
54
+ found_files = files & store.roots
55
+ found_files.each do |file|
56
+ if _active_file?(store[file])
57
+ results << storage_file.gsub('.yml', '').gsub("#{@folder}/", '')
58
+ end
54
59
  end
55
60
  end
56
61
  end
57
62
 
63
+ def _active_file?(file)
64
+ !file.to_s.split(',').delete_if { |s| s == '' || s == '0' }.empty?
65
+ end
66
+
58
67
  def get_store(file)
59
68
  dir = File.dirname("#{@folder}/#{file}")
60
69
  filename = File.basename(file) + '.yml'
@@ -1,4 +1,4 @@
1
1
  # version number
2
2
  module TestDiff
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grant Speelman