assert 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +55 -2
- data/lib/assert.rb +17 -4
- data/lib/assert/assert_runner.rb +16 -1
- data/lib/assert/cli.rb +3 -0
- data/lib/assert/version.rb +1 -1
- data/test/unit/assert_tests.rb +3 -3
- metadata +4 -4
data/README.md
CHANGED
@@ -194,7 +194,60 @@ end
|
|
194
194
|
Using the CLI:
|
195
195
|
|
196
196
|
```sh
|
197
|
-
$ assert [-t|--halt|--no-halt]
|
197
|
+
$ assert [-t|--halt-on-fail|--no-halt-on-fail]
|
198
|
+
```
|
199
|
+
|
200
|
+
### Changed Only
|
201
|
+
|
202
|
+
By default, Assert loads every test file in the path(s) it is given and runs the tests in those files. At times it is convenient to only run certain test files while you are actively developing on a feature. Assert can detect which test files have changes and only load those files:
|
203
|
+
|
204
|
+
In user/local settings file:
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
Assert.configure do |config|
|
208
|
+
config.changed_only true # not recommended - use the CLI with the `-c` flag
|
209
|
+
end
|
210
|
+
```
|
211
|
+
|
212
|
+
Using the CLI:
|
213
|
+
|
214
|
+
```sh
|
215
|
+
$ assert [-c|--changed-only|--no-changed-only]
|
216
|
+
```
|
217
|
+
|
218
|
+
#### Changed Test File Detection
|
219
|
+
|
220
|
+
The changed files are detected using two git commands by default:
|
221
|
+
|
222
|
+
```sh
|
223
|
+
git diff --no-ext-diff --name-only # changed files
|
224
|
+
git ls-files --others --exclude-standard # added files
|
225
|
+
```
|
226
|
+
|
227
|
+
The git cmds have ` -- #{test_paths}` appended to them to scope their results to just the test paths specified by the CLI and are run together using ` && `.
|
228
|
+
|
229
|
+
This, of course, assumes you are working in a git repository. If you are not or you want to use custom logic to determine the changed files, configure a custom proc. The proc should take a single parameter which is an array of test paths specified by the CLI.
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
Assert.configure do |config|
|
233
|
+
config.changed_files do |test_paths|
|
234
|
+
`git diff --name-only master -- #{test_paths.join(' ')}`.split("\n") # or whatever
|
235
|
+
end
|
236
|
+
end
|
237
|
+
```
|
238
|
+
|
239
|
+
If you just want to disable this feature completely:
|
240
|
+
|
241
|
+
```ruby
|
242
|
+
Assert.configure do |config|
|
243
|
+
|
244
|
+
# run nothing if the `-c` flag is given
|
245
|
+
config.changed_files{ |test_paths| [] }
|
246
|
+
|
247
|
+
# run all test paths if the `-c` flag is given
|
248
|
+
config.changed_files{ |test_paths| test_paths }
|
249
|
+
|
250
|
+
end
|
198
251
|
```
|
199
252
|
|
200
253
|
## Viewing Test Results
|
@@ -330,4 +383,4 @@ If submitting a Pull Request, please:
|
|
330
383
|
|
331
384
|
One note: please respect that Assert itself is intended to be the flexible, base-level, framework-type logic that should change little if at all. Pull requests for niche functionality or personal testing philosphy stuff will likely not be accepted.
|
332
385
|
|
333
|
-
If you wish to extend Assert for your niche purpose/desire/philosophy, please do so in it's own gem (preferrably named `assert-<whatever>`) that uses Assert as a dependency. When you do, tell us about it and we'll add to this README with a short description.
|
386
|
+
If you wish to extend Assert for your niche purpose/desire/philosophy, please do so in it's own gem (preferrably named `assert-<whatever>`) that uses Assert as a dependency. When you do, tell us about it and we'll add it to this README with a short description.
|
data/lib/assert.rb
CHANGED
@@ -45,8 +45,9 @@ module Assert
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
settings :view, :suite, :runner, :test_dir, :test_helper
|
49
|
-
settings :runner_seed, :capture_output, :halt_on_fail, :
|
48
|
+
settings :view, :suite, :runner, :test_dir, :test_helper, :changed_files
|
49
|
+
settings :runner_seed, :capture_output, :halt_on_fail, :changed_only
|
50
|
+
settings :debug
|
50
51
|
|
51
52
|
def initialize
|
52
53
|
@view = Assert::View::DefaultView.new($stdout)
|
@@ -55,10 +56,22 @@ module Assert
|
|
55
56
|
@test_dir = "test"
|
56
57
|
@test_helper = "helper.rb"
|
57
58
|
|
58
|
-
# default
|
59
|
+
# use git, by default, to determine which files have changes
|
60
|
+
@changed_files = proc do |test_paths|
|
61
|
+
cmds = [
|
62
|
+
"git diff --no-ext-diff --name-only", # changed files
|
63
|
+
"git ls-files --others --exclude-standard" # added files
|
64
|
+
]
|
65
|
+
cmd = cmds.map{ |c| "#{c} -- #{test_paths.join(' ')}" }.join(' && ')
|
66
|
+
puts " `#{cmd}`" if Assert.config.debug
|
67
|
+
`#{cmd}`.split("\n")
|
68
|
+
end
|
69
|
+
|
70
|
+
# default option values
|
59
71
|
@runner_seed = begin; srand; srand % 0xFFFF; end.to_i
|
60
|
-
@capture_output =
|
72
|
+
@capture_output = false
|
61
73
|
@halt_on_fail = true
|
74
|
+
@changed_only = false
|
62
75
|
@debug = false
|
63
76
|
end
|
64
77
|
|
data/lib/assert/assert_runner.rb
CHANGED
@@ -46,10 +46,25 @@ module Assert
|
|
46
46
|
private
|
47
47
|
|
48
48
|
def test_files(test_paths)
|
49
|
+
file_paths = if Assert.config.changed_only
|
50
|
+
changed_test_files(test_paths)
|
51
|
+
else
|
52
|
+
globbed_test_files(test_paths)
|
53
|
+
end
|
54
|
+
|
55
|
+
file_paths.select{ |p| is_test_file?(p) }.sort
|
56
|
+
end
|
57
|
+
|
58
|
+
def changed_test_files(test_paths)
|
59
|
+
puts "Loading only changed files:" if Assert.config.debug
|
60
|
+
globbed_test_files(Assert.config.changed_files.call(test_paths))
|
61
|
+
end
|
62
|
+
|
63
|
+
def globbed_test_files(test_paths)
|
49
64
|
test_paths.inject(Set.new) do |paths, path|
|
50
65
|
p = File.expand_path(path, Dir.pwd)
|
51
66
|
paths += Dir.glob("#{p}*") + Dir.glob("#{p}*/**/*")
|
52
|
-
end
|
67
|
+
end
|
53
68
|
end
|
54
69
|
|
55
70
|
def is_test_file?(path)
|
data/lib/assert/cli.rb
CHANGED
@@ -21,6 +21,9 @@ module Assert
|
|
21
21
|
option 'halt_on_fail', 'halt a test when it fails', {
|
22
22
|
:abbrev => 't'
|
23
23
|
}
|
24
|
+
option 'changed_only', 'only run test files with changes', {
|
25
|
+
:abbrev => 'c'
|
26
|
+
}
|
24
27
|
# show loaded test files, cli err backtraces, etc
|
25
28
|
option 'debug', 'run in debug mode'
|
26
29
|
end
|
data/lib/assert/version.rb
CHANGED
data/test/unit/assert_tests.rb
CHANGED
@@ -30,9 +30,9 @@ module Assert
|
|
30
30
|
desc "the Assert Config singleton"
|
31
31
|
subject { Config }
|
32
32
|
|
33
|
-
should have_imeths :suite, :view, :runner, :test_dir, :test_helper
|
34
|
-
should have_imeths :runner_seed, :capture_output, :halt_on_fail, :
|
35
|
-
should have_imeths :apply
|
33
|
+
should have_imeths :suite, :view, :runner, :test_dir, :test_helper, :changed_files
|
34
|
+
should have_imeths :runner_seed, :capture_output, :halt_on_fail, :changed_only
|
35
|
+
should have_imeths :debug, :apply
|
36
36
|
|
37
37
|
should "default the view, suite, and runner" do
|
38
38
|
assert_kind_of Assert::View::DefaultView, subject.view
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 2.
|
10
|
+
version: 2.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-
|
19
|
+
date: 2013-07-08 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: ansi
|