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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44702b3609807ac74dcf042d0286c7bcfa454b84
4
- data.tar.gz: 81066922a6b90393bf1e18ff17c23e5c715b482e
3
+ metadata.gz: 94f59b2f95b133bb72a50361d428a93ac6f62c23
4
+ data.tar.gz: 97c3fee8fcbafa082f24e21bfcb8aada5d251834
5
5
  SHA512:
6
- metadata.gz: 55201af622d4ffcb874180409b7a5ba73019646b979cb87e6feeb673adccc23b0dd81c22dce4e47fdaf72ec1642b1f2eae70cdcc09e7b489cb22e3c3bde0b1d0
7
- data.tar.gz: b8e12d40f4ddafe2cc61701bca6da224d13936ee8e8bf3f2839f62bada795d608543f96e1742d5dbb018d351044e408317f2aa8f04d4c01bcac2a154c918acea
6
+ metadata.gz: 639090edc53958e9aa7ced6cd476d1c5f974c4e1a6e84ec92bdfebace65d12f9e444535cdffb9145d2edc775d8cd6b46f42ea7807d0119d001d22fd875f11aaa
7
+ data.tar.gz: 3383686308e0d32881943b213a33b86adc4bbff700275c2a24f9ec97a9e3b03e490af7ddebbc41d7f28f81564813ae4be5e00582d77b58034af6839c5880e8b0
data/CHANGELOG.md ADDED
@@ -0,0 +1,32 @@
1
+ Change logs
2
+ ===========
3
+
4
+ master
5
+ ------
6
+
7
+ N/A
8
+
9
+
10
+ 0.2.0
11
+ -----
12
+
13
+ - [dev] #1 Setup CircleCI. and others
14
+ - [dev] #2 Add codeclimate
15
+ - [dev] #3 Fix bundle install command in rails directory. and others
16
+ - [bugfix] #4 Use hook scope names of rspec v2
17
+ - [bugfix] #8 Exit with real status
18
+ - [bugfix] #9 Fail to obtain current spec file path with RSpec 2
19
+ - [improvement] #12 Use original profiler
20
+ - [improvement] #14 Improve profiler
21
+ - [improvement] #15 Fully support parallel_tests
22
+ - [improvement] #19 Auto bundle exec
23
+ - [feature] #20 Run full tests
24
+ - [feature] #21 Add clear command
25
+
26
+ And many bugfixes and refactorings.
27
+
28
+
29
+ 0.1.0
30
+ -----
31
+
32
+ - The first release
data/README.md CHANGED
@@ -1,7 +1,19 @@
1
- delta_test [![Circle CI](https://circleci.com/gh/creasty/delta_test.svg?style=svg)](https://circleci.com/gh/creasty/delta_test)
1
+ :warning: **currently in development**
2
+
3
+ delta_test
2
4
  ==========
3
5
 
4
- **delta_test** analyzes your tests and runs only related tests for your file changes.
6
+ [![Circle CI](https://circleci.com/gh/creasty/delta_test.svg?style=shield)](https://circleci.com/gh/creasty/delta_test)
7
+ [![Code Climate](https://codeclimate.com/github/creasty/delta_test/badges/gpa.svg)](https://codeclimate.com/github/creasty/delta_test)
8
+ [![Test Coverage](https://codeclimate.com/github/creasty/delta_test/badges/coverage.svg)](https://codeclimate.com/github/creasty/delta_test/coverage)
9
+
10
+ **It's kinda "[delta update](http://en.wikipedia.org/wiki/Delta_update)" for RSpec.**
11
+
12
+ It basically do two things:
13
+
14
+ 1. Analyzes your tests and creates a dependencies table
15
+ 2. Based on the dependencies table and git diff,
16
+ only runs partial specs that are considered to be related to the file changes.
5
17
 
6
18
 
7
19
  Setup
@@ -48,19 +60,19 @@ end
48
60
  Usage
49
61
  -----
50
62
 
51
- First you'll need to run full tests to create **dependencies table**:
63
+ For the first time and whenever on master, it'll run full test cases to create **dependencies table**:
52
64
 
53
65
  ```bash
54
66
  $ git checkout master
55
- $ delta_test exec bundle exec rspec
67
+ $ delta_test exec rspec
56
68
  ```
57
69
 
58
- Then, on other branch:
70
+ And on other branch, it'll run only related tests for your changes from master:
59
71
 
60
72
  ```bash
61
73
  $ git checkout -b feature/something_awesome
62
74
  $ # Make changes & create commits...
63
- $ delta_test exec bundle exec rspec # runs only related tests for changes from master
75
+ $ delta_test exec rspec
64
76
  ```
65
77
 
66
78
 
@@ -71,7 +83,7 @@ Advanced usage
71
83
 
72
84
  ```
73
85
  usage: delta_test <command> [--base=<base>] [--head=<head>] [--verbose] [<args>]
74
- [-v]
86
+ [-v|--version]
75
87
 
76
88
  options:
77
89
  --base=<base> A branch or a commit id to diff from.
@@ -90,8 +102,46 @@ commands:
90
102
 
91
103
  table Show dependencies table.
92
104
 
93
- exec <script> Rxecute test script using delta_test.
94
- Run command something like `delta_test list | xargs script'.
105
+ exec <script> [-- <files>]
106
+ Execute test script using delta_test.
107
+ if <base> and <head> is the same commit or no dependencies table is found,
108
+ it'll run full test cases with a profile mode to create a table.
109
+ Otherwise, it'll run test script with only related spec files
110
+ passed by its arguments, like `delta_test list | xargs script'.
111
+
112
+ clear Clean up tables and caches.
113
+ ```
114
+
115
+ #### `exec` example
116
+
117
+ RSpec command is rewritten to:
118
+
119
+ ```bash
120
+ $ bundle exec rspec
121
+
122
+ $ bundle exec delta_test exec rspec
123
+ ```
124
+
125
+ With file lists:
126
+
127
+ ```bash
128
+ $ bundle exec rspec spec/{models,controllers}
129
+
130
+ $ bundle exec delta_test exec rspec -- spec/{models,controllers}
131
+ ```
132
+
133
+ And to colorize RSpec outputs, use `--tty` option of `rspec` command:
134
+
135
+ ```bash
136
+ $ bundle exec delta_test exec rspec --tty
137
+ ```
138
+
139
+ Also delta_test supports [parallel_tests](https://github.com/grosser/parallel_tests):
140
+
141
+ ```bash
142
+ $ bundle exec parallel_test -t rspec -n 4 spec/features
143
+
144
+ $ bundle exec delta_test exec parallel_test -t rspec -n 4 -- spec/features
95
145
  ```
96
146
 
97
147
  ### Configurations
@@ -106,6 +156,9 @@ patterns:
106
156
  exclude_patterns:
107
157
  - lib/batch/*.rb
108
158
 
159
+ full_test_patterns:
160
+ - Gemfile.lock
161
+
109
162
  custom_mappings:
110
163
  spec/features/i18n_spec.rb:
111
164
  - config/locales/**/*.yml
@@ -118,11 +171,7 @@ Testing
118
171
  Run units tests:
119
172
 
120
173
  ```bash
121
- $ rspec
122
-
123
- # or
124
-
125
- $ rake test
174
+ $ rake test # or you can use `rspec`
126
175
  ```
127
176
 
128
177
  Run integration tests:
data/Rakefile CHANGED
@@ -1,16 +1,29 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rake/extensiontask'
3
+
4
+ GEM_NAME = 'delta_test'
5
+ SO_NAME = 'delta_test_native'
6
+
7
+ Rake::ExtensionTask.new SO_NAME do |ext|
8
+ ext.ext_dir = "ext/#{GEM_NAME}"
9
+ ext.lib_dir = "lib/#{RUBY_VERSION.sub(/\.\d$/, '')}"
10
+ ext.cross_compile = true
11
+ ext.cross_platform = ['x86-mswin32-60', 'x86-mingw32-60']
12
+ end
2
13
 
3
14
  desc 'Run unit tests'
4
15
  task :test do
5
16
  s = system('bundle exec rspec')
6
- exit unless s
17
+ exit $? unless s
7
18
  end
8
19
 
9
20
  namespace :rails do
10
21
  desc 'Run rails tests'
11
22
  task :test do
12
- s = system('cd spec/rails && DELTA_TEST_ACTIVE=true bundle exec rspec')
13
- exit unless s
23
+ Bundler.with_clean_env do
24
+ s = system('cd spec/rails && DELTA_TEST_ACTIVE=true DELTA_TEST_VERBOSE=true bundle exec rspec')
25
+ exit $? unless s
26
+ end
14
27
  end
15
28
  end
16
29
 
data/circle.yml CHANGED
@@ -3,8 +3,15 @@ machine:
3
3
  version: 2.2.0
4
4
 
5
5
  dependencies:
6
+ cache_directories:
7
+ - spec/rails/vendor/bundle
6
8
  post:
7
- - cd spec/rails && bundle install
9
+ - cd spec/rails && (bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3)
10
+ - bundle exec rake compile
11
+
12
+ database:
13
+ override:
14
+ - cd spec/rails && bundle exec rake db:test:prepare
8
15
 
9
16
  test:
10
17
  override:
data/delta_test.gemspec CHANGED
@@ -8,23 +8,24 @@ Gem::Specification.new do |spec|
8
8
  spec.version = DeltaTest::VERSION
9
9
  spec.authors = ['Yuki Iwanaga']
10
10
  spec.email = ['yuki@creasty.com']
11
- spec.summary = %q{delta_test analyzes your tests and runs only related tests for your file changes}
11
+ spec.summary = %q{It's kinda "delta update" for RSpec}
12
12
  spec.description = %q{delta_test analyzes your tests and runs only related tests for your file changes}
13
13
  spec.homepage = 'http://github.com/creasty/delta_test'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.extensions = ['ext/delta_test/extconf.rb']
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
20
  spec.require_paths = ['lib']
20
21
 
21
22
  spec.required_ruby_version = '>= 2.0.0'
22
23
 
23
- spec.add_dependency 'ruby-prof'
24
-
25
24
  spec.add_development_dependency 'bundler', '~> 1.7'
25
+ spec.add_development_dependency 'codeclimate-test-reporter'
26
26
  spec.add_development_dependency 'fakefs'
27
27
  spec.add_development_dependency 'pry'
28
28
  spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rake-compiler'
29
30
  spec.add_development_dependency 'rspec', '>= 3.0'
30
31
  end
@@ -0,0 +1,154 @@
1
+ #include <stdio.h>
2
+ #include <stdbool.h>
3
+
4
+ #include "delta_test_native.h"
5
+
6
+ static VALUE mDeltaTest;
7
+ static VALUE mProfiler;
8
+
9
+ static dt_profiler_t *profile;
10
+
11
+
12
+ /*=== Helpers
13
+ ==============================================================================================*/
14
+ static void
15
+ dt_profiler_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE klass)
16
+ {
17
+ if (self == mDeltaTest || klass == mProfiler) {
18
+ return;
19
+ }
20
+
21
+ st_insert(profile->file_table, (st_data_t)rb_sourcefile(), Qtrue);
22
+ }
23
+
24
+ static void
25
+ dt_profiler_install_hook(VALUE self)
26
+ {
27
+ rb_add_event_hook(dt_profiler_event_hook, RUBY_EVENT_CALL, self);
28
+ }
29
+
30
+ static void
31
+ dt_profiler_uninstall_hook()
32
+ {
33
+ rb_remove_event_hook(dt_profiler_event_hook);
34
+ }
35
+
36
+
37
+ /*=== Initialize
38
+ ==============================================================================================*/
39
+ static void
40
+ dt_profiler_init()
41
+ {
42
+ profile = (dt_profiler_t *)malloc(sizeof(dt_profiler_t));
43
+
44
+ profile->running = Qfalse;
45
+ profile->file_table = st_init_strtable();
46
+ }
47
+
48
+
49
+ /*=== Class methods
50
+ ==============================================================================================*/
51
+ /**
52
+ * .clean! -> self
53
+ *
54
+ * Uninstalls event hook
55
+ */
56
+ static VALUE
57
+ dt_profiler_clean(VALUE self)
58
+ {
59
+ st_clear(profile->file_table);
60
+
61
+ profile->running = Qfalse;
62
+ dt_profiler_uninstall_hook();
63
+
64
+ return self;
65
+ }
66
+
67
+ /**
68
+ * .start! -> self
69
+ *
70
+ * Starts recording profile data
71
+ */
72
+ static VALUE
73
+ dt_profiler_start(VALUE self)
74
+ {
75
+ st_clear(profile->file_table);
76
+
77
+ if (profile->running == Qfalse) {
78
+ profile->running = Qtrue;
79
+ dt_profiler_install_hook(self);
80
+ }
81
+
82
+ return self;
83
+ }
84
+
85
+ /**
86
+ * .stop! -> self
87
+ *
88
+ * Stops collecting profile data
89
+ */
90
+ static VALUE
91
+ dt_profiler_stop(VALUE self)
92
+ {
93
+ if (profile->running == Qtrue) {
94
+ dt_profiler_uninstall_hook();
95
+ profile->running = Qfalse;
96
+ }
97
+
98
+ return self;
99
+ }
100
+
101
+ /**
102
+ * .running? -> Boolean
103
+ *
104
+ * Returns whether a profile is currently running
105
+ */
106
+ static VALUE
107
+ dt_profiler_running(VALUE self)
108
+ {
109
+ return profile->running;
110
+ }
111
+
112
+ /**
113
+ * .last_result -> Array
114
+ *
115
+ * Returns an array of source files
116
+ */
117
+ static int
118
+ dt_profiler_last_result_collect(st_data_t key, st_data_t value, st_data_t result)
119
+ {
120
+ rb_ary_push((VALUE)result, rb_str_new2((const char *)key));
121
+
122
+ return ST_CONTINUE;
123
+ }
124
+
125
+ static VALUE
126
+ dt_profiler_last_result(VALUE self)
127
+ {
128
+ if (profile->running) {
129
+ return Qnil;
130
+ }
131
+
132
+ VALUE result = rb_ary_new();
133
+ st_foreach(profile->file_table, dt_profiler_last_result_collect, result);
134
+ rb_gc_mark(result);
135
+
136
+ return result;
137
+ }
138
+
139
+
140
+ /*=== Define
141
+ ==============================================================================================*/
142
+ void Init_delta_test_native()
143
+ {
144
+ mDeltaTest = rb_define_module("DeltaTest");
145
+ mProfiler = rb_define_module_under(mDeltaTest, "Profiler");
146
+
147
+ dt_profiler_init();
148
+
149
+ rb_define_singleton_method(mProfiler, "clean!", dt_profiler_clean, 0);
150
+ rb_define_singleton_method(mProfiler, "start!", dt_profiler_start, 0);
151
+ rb_define_singleton_method(mProfiler, "stop!", dt_profiler_stop, 0);
152
+ rb_define_singleton_method(mProfiler, "running?", dt_profiler_running, 0);
153
+ rb_define_singleton_method(mProfiler, "last_result", dt_profiler_last_result, 0);
154
+ }
@@ -0,0 +1,15 @@
1
+ #ifndef __DELTA_TEST_NATIVE_H_LOADED__
2
+ #define __DELTA_TEST_NATIVE_H_LOADED__
3
+
4
+ #include <ruby.h>
5
+
6
+ #if RUBY_VERSION < 192
7
+ #error un-supported ruby version. Please upgrade to 1.9.3 or higher.
8
+ #endif
9
+
10
+ typedef struct {
11
+ VALUE running;
12
+ st_table *file_table;
13
+ } dt_profiler_t;
14
+
15
+ #endif // __DELTA_TEST_NATIVE_H_LOADED__
@@ -0,0 +1,12 @@
1
+ require 'mkmf'
2
+
3
+ if RUBY_VERSION < '1.9.3'
4
+ $stderr.puts("Ruby version #{RUBY_VERSION} is no longer supported. Please upgrade to 1.9.3 or higher")
5
+ exit 1
6
+ end
7
+
8
+ {
9
+ 'RUBY_VERSION' => RUBY_VERSION.gsub('.', '')
10
+ }.each { |k, v| $defs.push << '-D%s=%s' % [k, v] }
11
+
12
+ create_makefile('delta_test_native')
data/lib/delta_test.rb CHANGED
@@ -1,9 +1,15 @@
1
- require 'pathname'
2
-
3
1
  require_relative 'delta_test/version'
4
2
  require_relative 'delta_test/errors'
5
3
  require_relative 'delta_test/configuration'
6
4
 
5
+ # Load the C binding
6
+ begin
7
+ RUBY_VERSION =~ /(\d+.\d+)/
8
+ require_relative "#{$1}/delta_test_native"
9
+ rescue LoadError
10
+ require_relative 'delta_test_native'
11
+ end
12
+
7
13
  module DeltaTest
8
14
 
9
15
  ACTIVE_FLAG = 'DELTA_TEST_ACTIVE'