minitest-stately 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -9
- data/lib/minitest/stately/after_teardown.rb +9 -0
- data/lib/minitest/stately/reporter.rb +0 -4
- data/lib/minitest/stately/version.rb +1 -1
- data/lib/minitest/stately/watcher.rb +27 -12
- data/lib/minitest/stately_plugin.rb +9 -0
- data/test/minitest/stately/watcher_test.rb +40 -1
- data/test/minitest/stately_plugin_test.rb +5 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12d3996442703d16e374be803829c02fb3a49509
|
4
|
+
data.tar.gz: 1408bb41ba72f4578647327a970b31ba3ed2f086
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 003e6b9131129781909fd63c65f763e7be08eb41d6963dd19da5b0f2970f87612770522bc2ea97ae0c91dfa85e5bf92046a0d46e995c72eec9e7192c90a25471
|
7
|
+
data.tar.gz: 5f9c984ec2b43e75ee8f810c49f7a302fe37983882e9000f5a7a31baad101fc99cb886cf34f03243919dc9cc32d5dad58cb91cda01fad17509342a8f4d7b3855
|
data/README.md
CHANGED
@@ -21,14 +21,15 @@ Ruby 1.8.7 and REE are not supported. Sorry retro-Ruby fans!
|
|
21
21
|
## Usage
|
22
22
|
|
23
23
|
### Minitest::Stately.watch
|
24
|
-
Early in your test run (typically from `test_helper.rb`),
|
25
|
-
|
26
|
-
set
|
27
|
-
for changes.
|
24
|
+
Early in your test run (typically from `test_helper.rb`), set up the condition
|
25
|
+
blocks you want to watch for changes. The condition blocks run immediately to
|
26
|
+
set default values, and then after each test the blocks are executed again and
|
27
|
+
compared for changes. The name provided to watch is used strictly for output
|
28
|
+
in the final change report.
|
28
29
|
|
29
30
|
```
|
30
31
|
# Watch for freshly started threads
|
31
|
-
Minitest::Stately.watch("
|
32
|
+
Minitest::Stately.watch("thread count") do
|
32
33
|
Thread.list.count
|
33
34
|
end
|
34
35
|
```
|
@@ -40,11 +41,10 @@ like the following:
|
|
40
41
|
******************************
|
41
42
|
Minitest::Stately Changes!!!
|
42
43
|
******************************
|
43
|
-
Minitest::StatelyPluginTest#test_again:
|
44
|
-
Minitest::StatelyPluginTest#test_defined:
|
44
|
+
Minitest::StatelyPluginTest#test_again: thread count changed from '1' to '2'
|
45
|
+
Minitest::StatelyPluginTest#test_defined: thread count changed from '2' to '3'
|
45
46
|
```
|
46
47
|
|
47
|
-
|
48
48
|
### Minitest::Stately.run
|
49
49
|
Minitest::Stately can also register `run` blocks to be executed after each
|
50
50
|
test. This can be useful for clearing out leaked state between all tests in a
|
@@ -56,9 +56,28 @@ Minitest::Stately.run do
|
|
56
56
|
end
|
57
57
|
```
|
58
58
|
|
59
|
+
### Minitest::Stately.fail_if
|
60
|
+
Minitest::Stately also allows you to write conditions which will globally fail
|
61
|
+
any test if they become true.
|
62
|
+
|
63
|
+
```
|
64
|
+
# Fail if we get too many threads
|
65
|
+
Minitest::Stately.fail_if("so many threads") do
|
66
|
+
Thread.list.count > 10
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
If this condition was violated, you'd see a test failure like:
|
71
|
+
|
72
|
+
```
|
73
|
+
1) Failure:
|
74
|
+
Minitest::StatelyPluginTest#test_again [.../watcher.rb:54]:
|
75
|
+
so many threads
|
76
|
+
```
|
77
|
+
|
59
78
|
## Contributing
|
60
79
|
|
61
|
-
1. Fork it ( https://github.com/
|
80
|
+
1. Fork it ( https://github.com/jasonrclark/minitest-stately/fork )
|
62
81
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
82
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
64
83
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -2,34 +2,40 @@ module Minitest
|
|
2
2
|
module Stately
|
3
3
|
class Watcher
|
4
4
|
def initialize
|
5
|
-
@watch
|
6
|
-
@run
|
5
|
+
@watch = {}
|
6
|
+
@run = []
|
7
|
+
@failures = {}
|
7
8
|
|
8
9
|
@results = {}
|
9
10
|
@report = []
|
10
11
|
end
|
11
12
|
|
12
13
|
def watch(name, &blk)
|
13
|
-
@watch[name]
|
14
|
-
@results[
|
14
|
+
@watch[name] = blk
|
15
|
+
@results[name] = blk.call(nil)
|
15
16
|
end
|
16
17
|
|
17
18
|
def run(&blk)
|
18
19
|
@run << blk
|
19
20
|
end
|
20
21
|
|
22
|
+
def fail_if(name,&blk)
|
23
|
+
@failures[name] = blk
|
24
|
+
end
|
25
|
+
|
21
26
|
def record(result)
|
22
27
|
record_changes(result)
|
23
28
|
run_blocks()
|
29
|
+
check_failures(result)
|
24
30
|
end
|
25
31
|
|
26
32
|
def record_changes(result)
|
27
33
|
@watch.each do |name, blk|
|
28
|
-
value = blk.call
|
29
|
-
if value_changed?(
|
30
|
-
@report << message(result, name,
|
34
|
+
value = blk.call(result)
|
35
|
+
if value_changed?(name, value)
|
36
|
+
@report << message(result, name, value)
|
31
37
|
end
|
32
|
-
@results[
|
38
|
+
@results[name] = value
|
33
39
|
end
|
34
40
|
end
|
35
41
|
|
@@ -39,12 +45,21 @@ module Minitest
|
|
39
45
|
end
|
40
46
|
end
|
41
47
|
|
42
|
-
def
|
43
|
-
|
48
|
+
def check_failures(result)
|
49
|
+
failed = []
|
50
|
+
@failures.each do |name, blk|
|
51
|
+
failed << name if blk.call
|
52
|
+
end
|
53
|
+
|
54
|
+
result.flunk("#{failed.join(",")}") if failed.any?
|
55
|
+
end
|
56
|
+
|
57
|
+
def value_changed?(name, value)
|
58
|
+
@results[name] != value
|
44
59
|
end
|
45
60
|
|
46
|
-
def message(result, name,
|
47
|
-
"#{result.class.name}\##{result.name}: #{name} changed from
|
61
|
+
def message(result, name, value)
|
62
|
+
"#{result.class.name}\##{result.name}: #{name} changed from #{@results[name].inspect} to #{value.inspect}"
|
48
63
|
end
|
49
64
|
|
50
65
|
HEADER = <<-EOS
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'minitest/stately/after_teardown'
|
1
2
|
require 'minitest/stately/reporter'
|
2
3
|
require 'minitest/stately/watcher'
|
3
4
|
|
@@ -16,6 +17,14 @@ module Minitest
|
|
16
17
|
def self.run(&blk)
|
17
18
|
@watcher.run(&blk)
|
18
19
|
end
|
20
|
+
|
21
|
+
def self.fail_if(name, &blk)
|
22
|
+
@watcher.fail_if(name, &blk)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class ::Minitest::Test
|
27
|
+
include Minitest::Stately::AfterTeardown
|
19
28
|
end
|
20
29
|
|
21
30
|
def self.plugin_stately_init(options)
|
@@ -46,6 +46,22 @@ module Minitest
|
|
46
46
|
assert_changes(name, 2, 3)
|
47
47
|
end
|
48
48
|
|
49
|
+
def test_multiple_watches_last_one_wins
|
50
|
+
first = 0
|
51
|
+
second = 0
|
52
|
+
|
53
|
+
@watcher.watch("hey") { first += 1 }
|
54
|
+
@watcher.watch("hey") { second += 1 }
|
55
|
+
|
56
|
+
# Reset before we record so initial defaulting is wiped
|
57
|
+
first = 0
|
58
|
+
second = 0
|
59
|
+
@watcher.record(self)
|
60
|
+
|
61
|
+
assert_equal(0, first)
|
62
|
+
assert_equal(1, second)
|
63
|
+
end
|
64
|
+
|
49
65
|
def test_run
|
50
66
|
@boo = 1
|
51
67
|
@watcher.run do
|
@@ -56,9 +72,32 @@ module Minitest
|
|
56
72
|
assert_nil @boo
|
57
73
|
end
|
58
74
|
|
75
|
+
def test_fail_if
|
76
|
+
@watcher.fail_if("true") do
|
77
|
+
true
|
78
|
+
end
|
79
|
+
|
80
|
+
result = Minitest::Mock.new
|
81
|
+
result.expect(:flunk, nil, [String])
|
82
|
+
@watcher.record(result)
|
83
|
+
|
84
|
+
result.verify
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_doesnt_fail
|
88
|
+
@watcher.fail_if("won't fail") do
|
89
|
+
false
|
90
|
+
end
|
91
|
+
|
92
|
+
result = Minitest::Mock.new
|
93
|
+
@watcher.record(result)
|
94
|
+
|
95
|
+
result.verify
|
96
|
+
end
|
97
|
+
|
59
98
|
def assert_changes(name, old, new)
|
60
99
|
assert_includes @watcher.report, name
|
61
|
-
assert_includes @watcher.report, "
|
100
|
+
assert_includes @watcher.report, "#{old.inspect} to #{new.inspect}"
|
62
101
|
end
|
63
102
|
end
|
64
103
|
end
|
@@ -10,6 +10,11 @@ Minitest::Stately.run do
|
|
10
10
|
$clear_me = nil
|
11
11
|
end
|
12
12
|
|
13
|
+
Minitest::Stately.fail_if("too false to fail") do
|
14
|
+
# This condition should never fail
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
13
18
|
class Minitest::StatelyPluginTest < Minitest::Test
|
14
19
|
def test_defined
|
15
20
|
assert_nil $clear_me
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-stately
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason R. Clark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- LICENSE.txt
|
86
86
|
- README.md
|
87
87
|
- Rakefile
|
88
|
+
- lib/minitest/stately/after_teardown.rb
|
88
89
|
- lib/minitest/stately/reporter.rb
|
89
90
|
- lib/minitest/stately/version.rb
|
90
91
|
- lib/minitest/stately/watcher.rb
|