delta_test 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/README.md +63 -14
  4. data/Rakefile +16 -3
  5. data/circle.yml +8 -1
  6. data/delta_test.gemspec +4 -3
  7. data/ext/delta_test/delta_test_native.c +154 -0
  8. data/ext/delta_test/delta_test_native.h +15 -0
  9. data/ext/delta_test/extconf.rb +12 -0
  10. data/lib/delta_test.rb +8 -2
  11. data/lib/delta_test/cli.rb +108 -21
  12. data/lib/delta_test/configuration.rb +91 -35
  13. data/lib/delta_test/dependencies_table.rb +15 -1
  14. data/lib/delta_test/generator.rb +42 -29
  15. data/lib/delta_test/profiler.rb +5 -0
  16. data/lib/delta_test/related_spec_list.rb +67 -8
  17. data/lib/delta_test/spec_helpers.rb +9 -7
  18. data/lib/delta_test/version.rb +1 -1
  19. data/spec/lib/delta_test/cli_spec.rb +26 -5
  20. data/spec/lib/delta_test/configuration_spec.rb +12 -0
  21. data/spec/lib/delta_test/dependencies_table_spec.rb +35 -0
  22. data/spec/lib/delta_test/generator_spec.rb +34 -17
  23. data/spec/lib/delta_test/profiler_spec.rb +121 -0
  24. data/spec/lib/delta_test/related_spec_list_spec.rb +150 -34
  25. data/spec/lib/delta_test/spec_helpers_spec.rb +11 -5
  26. data/spec/rails/Gemfile +8 -2
  27. data/spec/rails/Gemfile.lock +37 -3
  28. data/spec/rails/app/models/category.rb +14 -0
  29. data/spec/rails/app/models/comment.rb +20 -0
  30. data/spec/rails/app/models/post.rb +23 -0
  31. data/spec/rails/app/models/post_categorizing.rb +14 -0
  32. data/spec/rails/app/models/user.rb +15 -0
  33. data/spec/rails/db/migrate/20150518052022_create_users.rb +9 -0
  34. data/spec/rails/db/migrate/20150518052057_create_posts.rb +11 -0
  35. data/spec/rails/db/migrate/20150518052332_create_comments.rb +11 -0
  36. data/spec/rails/db/migrate/20150518052523_create_categories.rb +9 -0
  37. data/spec/rails/db/migrate/20150518052604_create_post_categorizings.rb +10 -0
  38. data/spec/rails/db/schema.rb +59 -0
  39. data/spec/rails/spec/factories/categories.rb +5 -0
  40. data/spec/rails/spec/factories/comments.rb +8 -0
  41. data/spec/rails/spec/factories/post_categorizings.rb +6 -0
  42. data/spec/rails/spec/factories/posts.rb +7 -0
  43. data/spec/rails/spec/factories/users.rb +5 -0
  44. data/spec/rails/spec/models/category_spec.rb +3 -0
  45. data/spec/rails/spec/models/comment_spec.rb +3 -0
  46. data/spec/rails/spec/models/post_categorizing_spec.rb +3 -0
  47. data/spec/rails/spec/models/post_spec.rb +3 -0
  48. data/spec/rails/spec/models/user_spec.rb +20 -0
  49. data/spec/rails/spec/spec_helper.rb +53 -9
  50. data/spec/spec_helper.rb +2 -0
  51. metadata +79 -19
  52. data/lib/delta_test/analyzer.rb +0 -47
  53. data/spec/lib/delta_test/analyzer_spec.rb +0 -126
@@ -92,7 +92,7 @@ describe DeltaTest::RelatedSpecList do
92
92
 
93
93
  end
94
94
 
95
- describe '#related_spec_files' do
95
+ context 'Related spec files' do
96
96
 
97
97
  include_examples :_mock_table_and_changed_files
98
98
 
@@ -102,45 +102,49 @@ describe DeltaTest::RelatedSpecList do
102
102
  list.retrive_changed_files!(base, head)
103
103
  end
104
104
 
105
- describe 'Dependents' do
105
+ describe '#dependents' do
106
106
 
107
- let(:related_spec_files) do
108
- Set[
109
- 'spec/foo_spec.rb',
110
- 'spec/mixed_spec.rb',
111
- ]
112
- end
107
+ describe 'Dependents' do
108
+
109
+ let(:dependents) do
110
+ Set[
111
+ 'spec/foo_spec.rb',
112
+ 'spec/mixed_spec.rb',
113
+ ]
114
+ end
115
+
116
+ it 'should be included' do
117
+ expect(list.dependents).to eq(dependents)
118
+ end
113
119
 
114
- it 'should be included' do
115
- expect(list.related_spec_files).to eq(related_spec_files)
116
120
  end
117
121
 
118
- end
122
+ describe 'Modified spec files' do
119
123
 
120
- describe 'Modified spec files' do
124
+ let(:changed_files) do
125
+ [
126
+ 'lib/foo.rb',
127
+ 'spec/baz_spec.rb',
128
+ ]
129
+ end
121
130
 
122
- let(:changed_files) do
123
- [
124
- 'lib/foo.rb',
125
- 'spec/baz_spec.rb',
126
- ]
127
- end
131
+ let(:dependents) do
132
+ Set[
133
+ 'spec/foo_spec.rb',
134
+ 'spec/mixed_spec.rb',
135
+ 'spec/baz_spec.rb',
136
+ ]
137
+ end
128
138
 
129
- let(:related_spec_files) do
130
- Set[
131
- 'spec/foo_spec.rb',
132
- 'spec/mixed_spec.rb',
133
- 'spec/baz_spec.rb',
134
- ]
135
- end
139
+ it 'should be included' do
140
+ expect(list.dependents).to eq(dependents)
141
+ end
136
142
 
137
- it 'should be included' do
138
- expect(list.related_spec_files).to eq(related_spec_files)
139
143
  end
140
144
 
141
145
  end
142
146
 
143
- describe 'Custom dependents' do
147
+ describe '#customs' do
144
148
 
145
149
  let(:custom_mappings) do
146
150
  {
@@ -152,15 +156,12 @@ describe DeltaTest::RelatedSpecList do
152
156
 
153
157
  let(:changed_files) do
154
158
  [
155
- 'lib/foo.rb',
156
159
  'config/locales/something/en.yml',
157
160
  ]
158
161
  end
159
162
 
160
- let(:related_spec_files) do
163
+ let(:customs) do
161
164
  Set[
162
- 'spec/foo_spec.rb',
163
- 'spec/mixed_spec.rb',
164
165
  'spec/other_spec.rb',
165
166
  ]
166
167
  end
@@ -171,8 +172,123 @@ describe DeltaTest::RelatedSpecList do
171
172
  end
172
173
  end
173
174
 
174
- it 'should be included' do
175
- expect(list.related_spec_files).to eq(related_spec_files)
175
+ after do
176
+ DeltaTest.configure do |config|
177
+ config.custom_mappings = {}
178
+ end
179
+ end
180
+
181
+ it 'should include custom mapped files' do
182
+ expect(list.customs).to eq(customs)
183
+ end
184
+
185
+ end
186
+
187
+ describe '#full_tests?' do
188
+
189
+ context 'No file in full test patterns is changed' do
190
+
191
+ let(:changed_files) do
192
+ [
193
+ 'spec/other_spec.rb',
194
+ ]
195
+ end
196
+
197
+ it 'should return false' do
198
+ expect(list.full_tests?).to be(false)
199
+ end
200
+
201
+ end
202
+
203
+ context 'No file in full test patterns is changed' do
204
+
205
+ let(:full_test_patterns) do
206
+ [
207
+ 'spec/other_spec.rb',
208
+ ]
209
+ end
210
+
211
+ let(:changed_files) do
212
+ [
213
+ 'spec/other_spec.rb',
214
+ ]
215
+ end
216
+
217
+ before do
218
+ DeltaTest.configure do |config|
219
+ config.full_test_patterns = full_test_patterns
220
+ end
221
+ end
222
+
223
+ after do
224
+ DeltaTest.configure do |config|
225
+ config.full_test_patterns = []
226
+ end
227
+ end
228
+
229
+ it 'should return true' do
230
+ expect(list.full_tests?).to be(true)
231
+ end
232
+
233
+ end
234
+
235
+ end
236
+
237
+ describe '#full' do
238
+
239
+ let(:full_spec_files) do
240
+ Set[
241
+ 'spec/foo_spec.rb',
242
+ 'spec/bar_spec.rb',
243
+ 'spec/baz_spec.rb',
244
+ 'spec/other_spec.rb',
245
+ 'spec/mixed_spec.rb',
246
+ ]
247
+ end
248
+
249
+ it 'should return full spec files in the table' do
250
+ expect(list.full).to eq(full_spec_files)
251
+ end
252
+
253
+ end
254
+
255
+ describe '#related_spec_files' do
256
+
257
+ context 'If `full_tests?` is true' do
258
+
259
+ before do
260
+ allow(list).to receive(:full_tests?).and_return(true)
261
+ end
262
+
263
+ it 'should return full spec files' do
264
+ expect(list).to receive(:full)
265
+ expect(list).not_to receive(:dependents)
266
+ expect(list).not_to receive(:customs)
267
+
268
+ list.related_spec_files
269
+ end
270
+
271
+ end
272
+
273
+ context 'If `full_tests?` is false' do
274
+
275
+ let(:dependents) { Set['dependent_1'] }
276
+ let(:customs) { Set['custom_1'] }
277
+
278
+ before do
279
+ allow(list).to receive(:full_tests?).and_return(false)
280
+ allow(list).to receive(:dependents).and_return(dependents)
281
+ allow(list).to receive(:customs).and_return(customs)
282
+ end
283
+
284
+ it 'should return a union set of dependents and custom' do
285
+ expect(list).not_to receive(:full)
286
+ expect(list).to receive(:dependents)
287
+ expect(list).to receive(:customs)
288
+
289
+ expect(list.related_spec_files).to eq(dependents | customs)
290
+ end
291
+
176
292
  end
177
293
 
178
294
  end
@@ -16,14 +16,20 @@ describe DeltaTest::SpecHelpers do
16
16
  def metadata
17
17
  { file_path: 'spec/foo/bar.rb' }
18
18
  end
19
+
20
+ def file_path
21
+ metadata[:file_path]
22
+ end
19
23
  end
20
24
  end
21
25
 
22
26
  allow(DeltaTest).to receive(:active?).and_return(false)
23
27
  end
24
28
 
29
+ let(:generator) { DeltaTest::GeneratorSingleton.instance }
30
+
25
31
  it 'should define a global generator' do
26
- expect(defined?($delta_test_generator)).not_to be(false)
32
+ expect(defined?(generator)).not_to be(false)
27
33
  end
28
34
 
29
35
  describe 'when extending' do
@@ -31,12 +37,12 @@ describe DeltaTest::SpecHelpers do
31
37
  context 'before :all' do
32
38
 
33
39
  it 'should call it' do
34
- expect(@rspec_example_group).to receive(:before).with(:context)
40
+ expect(@rspec_example_group).to receive(:before).with(:all)
35
41
  @rspec_example_group.extend DeltaTest::SpecHelpers
36
42
  end
37
43
 
38
44
  it 'should start the generator' do
39
- expect($delta_test_generator).to receive(:start!).with("spec/foo/bar.rb")
45
+ expect(generator).to receive(:start!).with('spec/foo/bar.rb')
40
46
  @rspec_example_group.extend DeltaTest::SpecHelpers
41
47
  end
42
48
 
@@ -45,12 +51,12 @@ describe DeltaTest::SpecHelpers do
45
51
  context 'after :all' do
46
52
 
47
53
  it 'should call it' do
48
- expect(@rspec_example_group).to receive(:after).with(:context)
54
+ expect(@rspec_example_group).to receive(:after).with(:all)
49
55
  @rspec_example_group.extend DeltaTest::SpecHelpers
50
56
  end
51
57
 
52
58
  it 'should stop the generator' do
53
- expect($delta_test_generator).to receive(:stop!)
59
+ expect(generator).to receive(:stop!)
54
60
  @rspec_example_group.extend DeltaTest::SpecHelpers
55
61
  end
56
62
 
data/spec/rails/Gemfile CHANGED
@@ -2,14 +2,20 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '4.2.1'
4
4
 
5
+ gem 'haml-rails'
5
6
  gem 'sqlite3'
6
7
  gem 'therubyracer', platforms: :ruby
7
- gem 'haml-rails'
8
8
 
9
9
  group :development, :test do
10
+ gem 'capybara'
11
+ gem 'database_cleaner'
12
+ gem 'factory_girl_rails'
13
+ gem 'minitest'
14
+ gem 'poltergeist', github: 'teampoltergeist/poltergeist'
10
15
  gem 'pry-rails'
11
- gem 'spring'
12
16
  gem 'rspec-rails', '>= 3.2'
17
+ gem 'spork'
18
+ gem 'spring'
13
19
 
14
20
  gem 'delta_test', path: '../..'
15
21
  end
@@ -1,8 +1,17 @@
1
+ GIT
2
+ remote: git://github.com/teampoltergeist/poltergeist.git
3
+ revision: e3fc25919afb07960698785985f1051b9ea7f7ec
4
+ specs:
5
+ poltergeist (1.6.0)
6
+ capybara (~> 2.1)
7
+ cliver (~> 0.3.1)
8
+ multi_json (~> 1.0)
9
+ websocket-driver (>= 0.2.0)
10
+
1
11
  PATH
2
12
  remote: ../..
3
13
  specs:
4
- delta_test (0.0.1)
5
- ruby-prof
14
+ delta_test (0.1.0)
6
15
 
7
16
  GEM
8
17
  remote: https://rubygems.org/
@@ -44,9 +53,22 @@ GEM
44
53
  tzinfo (~> 1.1)
45
54
  arel (6.0.0)
46
55
  builder (3.2.2)
56
+ capybara (2.4.4)
57
+ mime-types (>= 1.16)
58
+ nokogiri (>= 1.3.3)
59
+ rack (>= 1.0.0)
60
+ rack-test (>= 0.5.4)
61
+ xpath (~> 2.0)
62
+ cliver (0.3.2)
47
63
  coderay (1.1.0)
64
+ database_cleaner (1.4.1)
48
65
  diff-lcs (1.2.5)
49
66
  erubis (2.7.0)
67
+ factory_girl (4.5.0)
68
+ activesupport (>= 3.0.0)
69
+ factory_girl_rails (4.5.0)
70
+ factory_girl (~> 4.5.0)
71
+ railties (>= 3.0.0)
50
72
  globalid (0.3.5)
51
73
  activesupport (>= 4.1.0)
52
74
  haml (4.0.6)
@@ -73,6 +95,7 @@ GEM
73
95
  mime-types (2.5)
74
96
  mini_portile (0.6.2)
75
97
  minitest (5.6.1)
98
+ multi_json (1.11.0)
76
99
  nokogiri (1.6.6.2)
77
100
  mini_portile (~> 0.6.0)
78
101
  pry (0.10.1)
@@ -127,11 +150,11 @@ GEM
127
150
  rspec-mocks (~> 3.2.0)
128
151
  rspec-support (~> 3.2.0)
129
152
  rspec-support (3.2.2)
130
- ruby-prof (0.15.8)
131
153
  ruby_parser (3.6.6)
132
154
  sexp_processor (~> 4.1)
133
155
  sexp_processor (4.5.1)
134
156
  slop (3.6.0)
157
+ spork (0.9.2)
135
158
  spring (1.3.5)
136
159
  sprockets (3.0.3)
137
160
  rack (~> 1.0)
@@ -148,16 +171,27 @@ GEM
148
171
  tilt (2.0.1)
149
172
  tzinfo (1.2.2)
150
173
  thread_safe (~> 0.1)
174
+ websocket-driver (0.5.4)
175
+ websocket-extensions (>= 0.1.0)
176
+ websocket-extensions (0.1.2)
177
+ xpath (2.0.0)
178
+ nokogiri (~> 1.3)
151
179
 
152
180
  PLATFORMS
153
181
  ruby
154
182
 
155
183
  DEPENDENCIES
184
+ capybara
185
+ database_cleaner
156
186
  delta_test!
187
+ factory_girl_rails
157
188
  haml-rails
189
+ minitest
190
+ poltergeist!
158
191
  pry-rails
159
192
  rails (= 4.2.1)
160
193
  rspec-rails (>= 3.2)
194
+ spork
161
195
  spring
162
196
  sqlite3
163
197
  therubyracer
@@ -0,0 +1,14 @@
1
+ class Category < ActiveRecord::Base
2
+
3
+ # Associations
4
+ #-----------------------------------------------
5
+ has_many :post_categorizings, dependent: :destroy
6
+
7
+
8
+ # Validations
9
+ #-----------------------------------------------
10
+ validates :name,
11
+ presence: true,
12
+ length: { maximum: 100 }
13
+
14
+ end
@@ -0,0 +1,20 @@
1
+ class Comment < ActiveRecord::Base
2
+
3
+ # Associations
4
+ #-----------------------------------------------
5
+ belongs_to :post
6
+ belongs_to :user
7
+
8
+
9
+ # Validations
10
+ #-----------------------------------------------
11
+ validates_associated :post
12
+ validates_associated :user
13
+
14
+ validates :post, presence: true
15
+ validates :user, presence: true
16
+ validates :body,
17
+ presence: true,
18
+ length: { maximum: 1000 }
19
+
20
+ end
@@ -0,0 +1,23 @@
1
+ class Post < ActiveRecord::Base
2
+
3
+ # Associations
4
+ #-----------------------------------------------
5
+ belongs_to :author, class_name: 'User'
6
+ has_many :comments, dependent: :destroy
7
+ has_many :post_categorizings, dependent: :destroy
8
+ has_many :categories, through: :post_categorizings
9
+
10
+
11
+ # Validations
12
+ #-----------------------------------------------
13
+ validates_associated :author
14
+
15
+ validates :author, presence: true
16
+ validates :title,
17
+ presence: true,
18
+ length: { maximum: 100 }
19
+ validates :body,
20
+ presence: true,
21
+ length: { maximum: 1000 }
22
+
23
+ end