minitest-stately 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8a4c3d450336f7408db315d24711c8fef8817c1e
4
+ data.tar.gz: 650c0031d535b36c429ba5988406ce07e3a36306
5
+ SHA512:
6
+ metadata.gz: 37b34454ad059078bd7215b2ac23e651dc9617e3962effc15daa091412e4f16d3b924844ce597ba75379676fa8b71a99edc82b09d55c54581f6e45024e7df282
7
+ data.tar.gz: 09bb894ba6d9350194625a86090987979f1a5d6946a6262e28f6f7c9377ab2a47e97d9fdde2076ef32c65ac4a62b585f5a8c204c22b9a6c106db4706d525ff81
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - jruby-19mode
7
+ - jruby-head
8
+ - rbx-2.2.7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in minitest-stately.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jason R. Clark
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Minitest::Stately
2
+ [![Gem Version](https://badge.fury.io/rb/minitest-stately.png)](http://badge.fury.io/rb/minitest-stately)
3
+ [![Build Status](https://api.travis-ci.org/jasonrclark/minitest-stately.png)](https://travis-ci.org/jasonrclark/minitest-stately)
4
+ [![Code Climate](https://codeclimate.com/github/jasonrclark/minitest-stately.png)](https://codeclimate.com/github/jasonrclark/hometown)
5
+ [![Coverage Status](https://coveralls.io/repos/jasonrclark/minitest-stately/badge.png)](https://coveralls.io/r/jasonrclark/hometown)
6
+
7
+ Find leaking state between tests
8
+
9
+ ## Requirements
10
+ Minitest 5.x is required for Minitest::Stately to work properly.
11
+
12
+ Tests are run against MRI 1.9.3 through 2.1.2, JRuby 1.7 (latest) and head, and
13
+ Rubinius 2.x (latest).
14
+
15
+ Ruby 1.8.7 and REE are not supported. Sorry retro-Ruby fans!
16
+
17
+ ## Installation
18
+
19
+ $ gem install minitest-stately
20
+
21
+ ## Usage
22
+
23
+ ### Minitest::Stately.watch
24
+ Early in your test run (typically from `test_helper.rb`), call to set up the
25
+ conditions to watch for changes in. The condition block is run immediately to
26
+ set a default value, and then run and compared after each test executes to look
27
+ for changes.
28
+
29
+ ```
30
+ # Watch for freshly started threads
31
+ Minitest::Stately.watch("condition name") do
32
+ Thread.list.count
33
+ end
34
+ ```
35
+
36
+ If there are changes during the test run for a condition, you'll see output
37
+ like the following:
38
+
39
+ ```
40
+ ******************************
41
+ Minitest::Stately Changes!!!
42
+ ******************************
43
+ Minitest::StatelyPluginTest#test_again: $boo changed from '0' to '1'
44
+ Minitest::StatelyPluginTest#test_defined: $boo changed from '1' to '2'
45
+ ```
46
+
47
+
48
+ ### Minitest::Stately.run
49
+ Minitest::Stately can also register `run` blocks to be executed after each
50
+ test. This can be useful for clearing out leaked state between all tests in a
51
+ suite.
52
+
53
+ ```
54
+ Minitest::Stately.run do
55
+ $silly_global_state = nil
56
+ end
57
+ ```
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it ( https://github.com/[my-github-username]/minitest-stately/fork )
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ task :default => :test
6
+
7
+ Rake::TestTask.new do |test|
8
+ test.verbose = true
9
+ test.libs << "test"
10
+ test.libs << "lib"
11
+ test.test_files = FileList['test/**/*_test.rb']
12
+ end
@@ -0,0 +1,17 @@
1
+ module Minitest
2
+ module Stately
3
+ class Reporter < Minitest::Reporter
4
+ def initialize(options={})
5
+ super(options.delete(:io) || $stdout, options)
6
+ end
7
+
8
+ def record(result)
9
+ Minitest::Stately.watcher.record(result)
10
+ end
11
+
12
+ def report
13
+ io.puts(Minitest::Stately.watcher.report)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module Minitest
2
+ module Stately
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,64 @@
1
+ module Minitest
2
+ module Stately
3
+ class Watcher
4
+ def initialize
5
+ @watch = {}
6
+ @run = []
7
+
8
+ @results = {}
9
+ @report = []
10
+ end
11
+
12
+ def watch(name, &blk)
13
+ @watch[name] = blk
14
+ @results[blk] = blk.call
15
+ end
16
+
17
+ def run(&blk)
18
+ @run << blk
19
+ end
20
+
21
+ def record(result)
22
+ record_changes(result)
23
+ run_blocks()
24
+ end
25
+
26
+ def record_changes(result)
27
+ @watch.each do |name, blk|
28
+ value = blk.call
29
+ if value_changed?(blk, value)
30
+ @report << message(result, name, blk, value)
31
+ end
32
+ @results[blk] = value
33
+ end
34
+ end
35
+
36
+ def run_blocks()
37
+ @run.each do |blk|
38
+ blk.call
39
+ end
40
+ end
41
+
42
+ def value_changed?(blk, value)
43
+ @results[blk] != value
44
+ end
45
+
46
+ def message(result, name, blk, value)
47
+ "#{result.class.name}\##{result.name}: #{name} changed from '#{@results[blk]}' to '#{value}'"
48
+ end
49
+
50
+ HEADER = <<-EOS
51
+
52
+ ******************************
53
+ Minitest::Stately Changes!!!
54
+ ******************************
55
+ EOS
56
+
57
+ def report
58
+ return "" if @report.empty?
59
+
60
+ HEADER + @report.join("\n") + "\n\n"
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,24 @@
1
+ require 'minitest/stately/reporter'
2
+ require 'minitest/stately/watcher'
3
+
4
+ module Minitest
5
+ module Stately
6
+ @watcher = Watcher.new
7
+
8
+ def self.watcher
9
+ @watcher
10
+ end
11
+
12
+ def self.watch(name, &blk)
13
+ @watcher.watch(name, &blk)
14
+ end
15
+
16
+ def self.run(&blk)
17
+ @watcher.run(&blk)
18
+ end
19
+ end
20
+
21
+ def self.plugin_stately_init(options)
22
+ self.reporter.reporters << Minitest::Stately::Reporter.new
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'minitest/stately/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "minitest-stately"
8
+ spec.version = Minitest::Stately::VERSION
9
+ spec.authors = ["Jason R. Clark"]
10
+ spec.email = ["jason@jasonrclark.net"]
11
+ spec.summary = %q{Find leaking state between tests}
12
+ spec.description = %q{Find and clear leaking state between individual test executions}
13
+ spec.homepage = "http://github.com/jasonrclark/minitest-stately"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'minitest', '~> 5.0', '>= 5.0.0'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 10.2"
25
+ spec.add_development_dependency "coveralls", "~> 0.7"
26
+ end
@@ -0,0 +1,65 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "test_helper"))
2
+ require 'minitest/stately/watcher'
3
+
4
+ module Minitest
5
+ module Stately
6
+ class WatcherTest < Minitest::Test
7
+ def setup
8
+ @watcher = Watcher.new
9
+ end
10
+
11
+ def test_watcher_no_change
12
+ @boo = 1
13
+ @watcher.watch("@boo") do
14
+ @boo
15
+ end
16
+
17
+ @watcher.record(self)
18
+ assert_empty @watcher.report
19
+ end
20
+
21
+ def test_watcher_change_from_initial_default
22
+ @boo = 1
23
+ @watcher.watch("@boo") do
24
+ @boo
25
+ end
26
+
27
+ @boo += 1
28
+ @watcher.record(self)
29
+
30
+ assert_changes(name, 1, 2)
31
+ end
32
+
33
+ def test_multiple_changes
34
+ @boo = 1
35
+ @watcher.watch("@boo") do
36
+ @boo
37
+ end
38
+
39
+ @boo += 1
40
+ @watcher.record(self)
41
+
42
+ @boo += 1
43
+ @watcher.record(self)
44
+
45
+ assert_changes(name, 1, 2)
46
+ assert_changes(name, 2, 3)
47
+ end
48
+
49
+ def test_run
50
+ @boo = 1
51
+ @watcher.run do
52
+ @boo = nil
53
+ end
54
+
55
+ @watcher.record(self)
56
+ assert_nil @boo
57
+ end
58
+
59
+ def assert_changes(name, old, new)
60
+ assert_includes @watcher.report, name
61
+ assert_includes @watcher.report, "'#{old}' to '#{new}'"
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "test_helper"))
2
+ require 'minitest/stately_plugin'
3
+
4
+ $boo = 0
5
+ Minitest::Stately.watch("$boo") do
6
+ $boo
7
+ end
8
+
9
+ Minitest::Stately.run do
10
+ $clear_me = nil
11
+ end
12
+
13
+ class Minitest::StatelyPluginTest < Minitest::Test
14
+ def test_defined
15
+ assert_nil $clear_me
16
+ $boo += 1
17
+ $clear_me = true
18
+ end
19
+
20
+ def test_again
21
+ assert_nil $clear_me
22
+ $boo += 1
23
+ $clear_me = true
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ if ENV["CI"]
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+ end
5
+
6
+ gem 'minitest'
7
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-stately
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason R. Clark
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '5.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.6'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.6'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.2'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.2'
61
+ - !ruby/object:Gem::Dependency
62
+ name: coveralls
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.7'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0.7'
75
+ description: Find and clear leaking state between individual test executions
76
+ email:
77
+ - jason@jasonrclark.net
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".travis.yml"
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - lib/minitest/stately/reporter.rb
89
+ - lib/minitest/stately/version.rb
90
+ - lib/minitest/stately/watcher.rb
91
+ - lib/minitest/stately_plugin.rb
92
+ - minitest-stately.gemspec
93
+ - test/minitest/stately/watcher_test.rb
94
+ - test/minitest/stately_plugin_test.rb
95
+ - test/test_helper.rb
96
+ homepage: http://github.com/jasonrclark/minitest-stately
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.2.2
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Find leaking state between tests
120
+ test_files:
121
+ - test/minitest/stately/watcher_test.rb
122
+ - test/minitest/stately_plugin_test.rb
123
+ - test/test_helper.rb
124
+ has_rdoc: