delta_test 0.2.0 → 1.0.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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +22 -34
  4. data/Rakefile +5 -2
  5. data/bin/delta_test +1 -1
  6. data/circle.yml +5 -1
  7. data/delta_test.gemspec +1 -1
  8. data/lib/delta_test/cli/command_base.rb +114 -0
  9. data/lib/delta_test/cli/exec_command.rb +95 -0
  10. data/lib/delta_test/cli/help_command.rb +38 -0
  11. data/lib/delta_test/cli/specs_command.rb +43 -0
  12. data/lib/delta_test/cli/stats_clean_command.rb +20 -0
  13. data/lib/delta_test/cli/stats_save_command.rb +67 -0
  14. data/lib/delta_test/cli/stats_show_command.rb +46 -0
  15. data/lib/delta_test/cli/version_command.rb +13 -0
  16. data/lib/delta_test/cli.rb +22 -296
  17. data/lib/delta_test/configuration.rb +57 -42
  18. data/lib/delta_test/errors.rb +24 -0
  19. data/lib/delta_test/generator.rb +4 -24
  20. data/lib/delta_test/git.rb +161 -80
  21. data/lib/delta_test/profiler.rb +8 -0
  22. data/lib/delta_test/related_spec_list.rb +14 -9
  23. data/lib/delta_test/stats.rb +41 -0
  24. data/lib/delta_test/version.rb +2 -2
  25. data/lib/delta_test.rb +14 -9
  26. data/spec/lib/delta_test/cli/command_base_spec.rb +164 -0
  27. data/spec/lib/delta_test/cli/exec_command_spec.rb +128 -0
  28. data/spec/lib/delta_test/cli/help_command_spec.rb +17 -0
  29. data/spec/lib/delta_test/cli/specs_command_spec.rb +54 -0
  30. data/spec/lib/delta_test/cli/stats_clean_command_spec.rb +39 -0
  31. data/spec/lib/delta_test/cli/stats_save_command_spec.rb +207 -0
  32. data/spec/lib/delta_test/cli/stats_show_command_spec.rb +52 -0
  33. data/spec/lib/delta_test/cli/version_command_spec.rb +17 -0
  34. data/spec/lib/delta_test/cli_spec.rb +47 -386
  35. data/spec/lib/delta_test/configuration_spec.rb +99 -47
  36. data/spec/lib/delta_test/dependencies_table_spec.rb +1 -1
  37. data/spec/lib/delta_test/generator_spec.rb +3 -3
  38. data/spec/lib/delta_test/git_spec.rb +291 -50
  39. data/spec/lib/delta_test/profiler_spec.rb +3 -3
  40. data/spec/lib/delta_test/related_spec_list_spec.rb +12 -14
  41. data/spec/lib/delta_test/stats_spec.rb +89 -0
  42. data/spec/lib/delta_test/utils_spec.rb +4 -4
  43. data/spec/lib/delta_test_spec.rb +13 -4
  44. data/spec/rails/Gemfile.lock +5 -2
  45. data/spec/rails/app/models/category.rb +4 -0
  46. data/spec/rails/delta_test.yml +4 -3
  47. data/spec/rails/spec/models/category_spec.rb +4 -0
  48. data/spec/spec_helper.rb +9 -2
  49. data/spec/supports/create_table_file.rb +11 -1
  50. data/visual.jpg +0 -0
  51. metadata +32 -4
@@ -0,0 +1,54 @@
1
+ require 'delta_test/cli/specs_command'
2
+
3
+ describe DeltaTest::CLI::SpecsCommand do
4
+
5
+ let(:command) { DeltaTest::CLI::SpecsCommand.new([]) }
6
+
7
+ let(:related_spec_files) do
8
+ [
9
+ 'spec/foo_spec.rb',
10
+ ]
11
+ end
12
+
13
+ let(:base_commit) { '1111111111111111111111111111111111111111' }
14
+
15
+ before do
16
+ allow(command.list).to receive(:load_table!).and_return(nil)
17
+ allow(command.list).to receive(:retrive_changed_files!).and_return(nil)
18
+ allow(command.list).to receive(:related_spec_files).and_return(related_spec_files)
19
+
20
+ allow(command.stats).to receive(:base_commit).and_return(base_commit)
21
+ end
22
+
23
+ describe '#invoke!' do
24
+
25
+ it 'should raise an error if a base commit does not exist' do
26
+ allow(command.stats).to receive(:base_commit).and_return(nil)
27
+
28
+ expect {
29
+ command.invoke!
30
+ }.to raise_error(DeltaTest::StatsNotFoundError)
31
+ end
32
+
33
+ it 'should load a table file and retrive changed files' do
34
+ expect(command.list).to receive(:load_table!).once
35
+ expect(command.list).to receive(:retrive_changed_files!).once
36
+
37
+ expect {
38
+ command.invoke!
39
+ }.not_to raise_error
40
+ end
41
+
42
+ it 'should show a list of related spec files' do
43
+ expect(command.list).to receive(:load_table!).once
44
+ expect(command.list).to receive(:retrive_changed_files!).once
45
+ expect(command.list).to receive(:related_spec_files).once
46
+
47
+ expect {
48
+ command.invoke!
49
+ }.to output(/foo_spec\.rb/).to_stdout
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,39 @@
1
+ require 'delta_test/cli/stats_clean_command'
2
+
3
+ describe DeltaTest::CLI::StatsCleanCommand do
4
+
5
+ let(:tmp_dir) { DeltaTest.config.tmp_table_file.parent }
6
+ let(:command) { DeltaTest::CLI::StatsCleanCommand.new([]) }
7
+
8
+ describe '#invoke!' do
9
+
10
+ it 'should call cleanup_tmp_table_files' do
11
+ expect(command).to receive(:cleanup_tmp_table_files).and_return(nil)
12
+ command.invoke!
13
+ end
14
+
15
+ end
16
+
17
+ describe '#cleanup_tmp_table_files' do
18
+
19
+ it 'should not raise any error if a tmporary directory does not exist' do
20
+ expect(File.directory?(tmp_dir)).to be(false)
21
+ expect {
22
+ command.invoke!
23
+ }.not_to raise_error
24
+ end
25
+
26
+ it 'should delete all files in the temporary directory' do
27
+ FakeFS::FileSystem.add(tmp_dir.join('foo'), FakeFS::FakeFile.new)
28
+ FakeFS::FileSystem.add(tmp_dir.join('bar'), FakeFS::FakeFile.new)
29
+
30
+ expect(File.directory?(tmp_dir)).to be(true)
31
+ expect {
32
+ command.cleanup_tmp_table_files
33
+ }.not_to raise_error
34
+ expect(File.directory?(tmp_dir)).to be(false)
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,207 @@
1
+ require 'delta_test/cli/stats_save_command'
2
+ require 'delta_test/stats'
3
+
4
+ describe DeltaTest::CLI::StatsSaveCommand do
5
+
6
+ let(:command) { DeltaTest::CLI::StatsSaveCommand.new([]) }
7
+
8
+ let(:head_commit) { '1111111111111111111111111111111111111111' }
9
+
10
+ let(:tmp_dir) { DeltaTest.config.tmp_table_file.parent }
11
+
12
+ let(:tmp_table_1_path) { tmp_dir.join('table_1.marshal') }
13
+ let(:tmp_table_1) do
14
+ DeltaTest::DependenciesTable.new.tap do |table|
15
+ table['spec/foo_spec.rb'] << 'lib/foo.rb'
16
+ table['spec/bar_spec.rb'] << 'lib/bar.rb'
17
+ table['spec/mixed_spec.rb'] << 'lib/foo.rb'
18
+
19
+ FakeFS::FileSystem.add(tmp_table_1_path, FakeFS::FakeFile.new)
20
+ table.dump(tmp_table_1_path)
21
+ end
22
+ end
23
+
24
+ let(:tmp_table_2_path) { tmp_dir.join('table_2.marshal') }
25
+ let(:tmp_table_2) do
26
+ DeltaTest::DependenciesTable.new.tap do |table|
27
+ table['spec/baz_spec.rb'] << 'lib/baz.rb'
28
+ table['spec/mixed_spec.rb'] << 'lib/bar.rb'
29
+
30
+ FakeFS::FileSystem.add(tmp_table_2_path, FakeFS::FakeFile.new)
31
+ table.dump(tmp_table_2_path)
32
+ end
33
+ end
34
+
35
+ let(:whole_table_path) { command.stats.table_file_path }
36
+ let(:whole_table) do
37
+ DeltaTest::DependenciesTable.new.tap do |table|
38
+ table['spec/foo_spec.rb'] << 'lib/foo.rb'
39
+ table['spec/bar_spec.rb'] << 'lib/bar.rb'
40
+ table['spec/baz_spec.rb'] << 'lib/baz.rb'
41
+ table['spec/mixed_spec.rb'] << 'lib/foo.rb'
42
+ table['spec/mixed_spec.rb'] << 'lib/bar.rb'
43
+ end
44
+ end
45
+
46
+ before do
47
+ allow_any_instance_of(DeltaTest::Git).to receive(:rev_parse).with('HEAD').and_return(head_commit)
48
+ end
49
+
50
+ describe '#invoke!' do
51
+
52
+ it 'should execute procedures' do
53
+ expect(command).to receive(:load_tmp_table_files).and_return(nil).once.ordered
54
+ expect(command).to receive(:cleanup_tmp_table_files).and_return(nil).once.ordered
55
+ expect(command).to receive(:save_table_file).and_return(nil).once.ordered
56
+ expect(command).to receive(:stage_table_file).and_return(nil).once.ordered
57
+ expect(command).to receive(:sync_table_file).and_return(nil).once.ordered
58
+ command.invoke!
59
+ end
60
+
61
+ context 'with --no-sync' do
62
+
63
+ let(:command) { DeltaTest::CLI::StatsSaveCommand.new(['--no-sync']) }
64
+
65
+ it 'should not sync the repository' do
66
+ expect(command).to receive(:load_tmp_table_files).and_return(nil).once.ordered
67
+ expect(command).to receive(:cleanup_tmp_table_files).and_return(nil).once.ordered
68
+ expect(command).to receive(:save_table_file).and_return(nil).once.ordered
69
+ expect(command).to receive(:stage_table_file).and_return(nil).once.ordered
70
+ expect(command).not_to receive(:sync_table_file)
71
+ command.invoke!
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
78
+ describe '#tmp_table_files' do
79
+
80
+ before do
81
+ tmp_table_1
82
+ tmp_table_2
83
+ end
84
+
85
+ it 'should return all table files in the temporary directory' do
86
+ expect(command.tmp_table_files).to eq([tmp_table_1_path.to_s, tmp_table_2_path.to_s])
87
+ end
88
+
89
+ end
90
+
91
+ describe '#stats' do
92
+
93
+ it 'should initialize Stats with head: true' do
94
+ expect(DeltaTest::Stats).to receive(:new).with(head: true).and_return(nil).once
95
+ command.stats
96
+ end
97
+
98
+ end
99
+
100
+ describe '#load_tmp_table_files' do
101
+
102
+ before do
103
+ tmp_table_1
104
+ tmp_table_2
105
+ end
106
+
107
+ it 'should load all temporary tables and merge them into one' do
108
+ expect(command.table).to be_empty
109
+ expect {
110
+ command.load_tmp_table_files
111
+ }.not_to raise_error
112
+ expect(command.table).to eq(whole_table)
113
+ end
114
+
115
+ end
116
+
117
+ describe '#cleanup_tmp_table_files' do
118
+
119
+ before do
120
+ tmp_table_1
121
+ tmp_table_2
122
+ end
123
+
124
+ it 'should load all temporary tables and merge them into one' do
125
+ expect(File.directory?(tmp_dir)).to be(true)
126
+ expect {
127
+ command.cleanup_tmp_table_files
128
+ }.not_to raise_error
129
+ expect(File.directory?(tmp_dir)).to be(false)
130
+ end
131
+
132
+ end
133
+
134
+ describe '#save_table_file' do
135
+
136
+ before do
137
+ tmp_table_1
138
+ tmp_table_2
139
+ end
140
+
141
+ it 'should save the table file' do
142
+ expect(File.exist?(whole_table_path)).to be(false)
143
+ expect {
144
+ command.save_table_file
145
+ }.not_to raise_error
146
+ expect(File.exist?(whole_table_path)).to be(true)
147
+ end
148
+
149
+ end
150
+
151
+ describe '#stage_table_file' do
152
+
153
+ before do
154
+ FakeFS::FileSystem.add(whole_table_path, FakeFS::FakeFile.new)
155
+ whole_table.dump(whole_table_path)
156
+ end
157
+
158
+ it 'should add and commit the table file' do
159
+ expect(command.stats.stats_git).to receive(:add).with(whole_table_path).and_return(true)
160
+ expect(command.stats.stats_git).to receive(:commit).with(head_commit).and_return(true)
161
+ expect {
162
+ command.stage_table_file
163
+ }.not_to raise_error
164
+ end
165
+
166
+ it 'should raise an error if failed to stage the table file' do
167
+ expect(command.stats.stats_git).to receive(:add).with(whole_table_path).and_return(true)
168
+ expect(command.stats.stats_git).to receive(:commit).with(head_commit).and_return(false)
169
+ expect {
170
+ command.stage_table_file
171
+ }.to raise_error(DeltaTest::TableFileStageError)
172
+ end
173
+
174
+ end
175
+
176
+ describe '#sync_table_file' do
177
+
178
+ it 'should do nothing if no remote is configured' do
179
+ allow(command.stats.stats_git).to receive(:has_remote?).and_return(false)
180
+ expect(command.stats.stats_git).not_to receive(:pull)
181
+ expect(command.stats.stats_git).not_to receive(:push)
182
+ expect {
183
+ command.sync_table_file
184
+ }.not_to raise_error
185
+ end
186
+
187
+ it 'should pull and push' do
188
+ allow(command.stats.stats_git).to receive(:has_remote?).and_return(true)
189
+ expect(command.stats.stats_git).to receive(:pull).and_return(true)
190
+ expect(command.stats.stats_git).to receive(:push).and_return(true)
191
+ expect {
192
+ command.sync_table_file
193
+ }.not_to raise_error
194
+ end
195
+
196
+ it 'should raise an error if failed to sync the repository' do
197
+ allow(command.stats.stats_git).to receive(:has_remote?).and_return(true)
198
+ expect(command.stats.stats_git).to receive(:pull).and_return(true)
199
+ expect(command.stats.stats_git).to receive(:push).and_return(false)
200
+ expect {
201
+ command.sync_table_file
202
+ }.to raise_error(DeltaTest::StatsRepositorySyncError)
203
+ end
204
+
205
+ end
206
+
207
+ end
@@ -0,0 +1,52 @@
1
+ require 'delta_test/cli/stats_show_command'
2
+
3
+ describe DeltaTest::CLI::StatsShowCommand do
4
+
5
+ let(:command) { DeltaTest::CLI::StatsShowCommand.new([]) }
6
+
7
+ let(:table) do
8
+ {
9
+ 'spec/foo_spec.rb' => ['lib/foo.rb']
10
+ }
11
+ end
12
+
13
+ let(:base_commit) { '1111111111111111111111111111111111111111' }
14
+
15
+ before do
16
+ allow(command.list).to receive(:load_table!).and_return(nil)
17
+ allow(command.list).to receive(:table).and_return(table)
18
+
19
+ allow(command.stats).to receive(:base_commit).and_return(base_commit)
20
+ end
21
+
22
+ describe '#invoke!' do
23
+
24
+ it 'should raise an error if a base commit does not exist' do
25
+ allow(command.stats).to receive(:base_commit).and_return(nil)
26
+
27
+ expect {
28
+ command.invoke!
29
+ }.to raise_error(DeltaTest::StatsNotFoundError)
30
+ end
31
+
32
+ it 'should load a table file' do
33
+ expect(command.list).to receive(:load_table!)
34
+ expect(command.list).to receive(:table)
35
+
36
+ expect {
37
+ command.invoke!
38
+ }.not_to raise_error
39
+ end
40
+
41
+ it 'should show the table contents' do
42
+ expect(command.list).to receive(:load_table!)
43
+ expect(command.list).to receive(:table)
44
+
45
+ expect {
46
+ command.invoke!
47
+ }.to output(/foo_spec\.rb/).to_stdout
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,17 @@
1
+ require 'delta_test/cli/version_command'
2
+
3
+ describe DeltaTest::CLI::VersionCommand do
4
+
5
+ let(:command) { DeltaTest::CLI::VersionCommand.new([]) }
6
+
7
+ describe '#invoke!' do
8
+
9
+ it 'should print help' do
10
+ expect {
11
+ command.invoke!
12
+ }.to output(/v\d+\.\d+.\d+/).to_stdout
13
+ end
14
+
15
+ end
16
+
17
+ end