busted 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.ruby-version +1 -0
- data/CONTRIBUTING.md +24 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +85 -0
- data/Rakefile +9 -0
- data/busted.gemspec +29 -0
- data/lib/busted/version.rb +3 -0
- data/lib/busted.rb +40 -0
- data/test/busted_test.rb +91 -0
- data/test/test_helper.rb +3 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9c73c2265d2342d47aa6795e0dd804bef8f2ce8c
|
4
|
+
data.tar.gz: 7004ab5cba0caa4c832ed49e5d5a7475e0dfb33a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 275bb9449f497c20eaf8306b6ef69c9647763577c9a6c5be863a339623259036e669613dcc1774c0b3dab810861170ae59621dec8df2cc72abd7dd326b2d2d08
|
7
|
+
data.tar.gz: 047d454ed1d7a07ac8506ae8828de5daf780910c2fa07eed6081f38c72cb7de2aa5515a2cd83902dea78efe0d588ca8190b04008f5c00ab89cf4579c5f5fd186
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.0-dev
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
Thanks for using and improving Busted! If you'd like to help out, check out
|
4
|
+
[the project's issues list][issues] for ideas on what could be improved.
|
5
|
+
If there's an idea you'd like to propose, or a design change, feel free to
|
6
|
+
file a new issue. For bonus brownie points, [pull requests][pr] are always
|
7
|
+
welcome.
|
8
|
+
|
9
|
+
## Running the Tests
|
10
|
+
|
11
|
+
To run the full suite:
|
12
|
+
|
13
|
+
`$ bundle exec rake`
|
14
|
+
|
15
|
+
To run a specific test file:
|
16
|
+
|
17
|
+
`$ bundle exec ruby -Itest test/busted_test.rb`
|
18
|
+
|
19
|
+
To run a specific test:
|
20
|
+
|
21
|
+
`$ bundle exec ruby -Itest test/busted_test.rb -n test_cache_with_new_constant`
|
22
|
+
|
23
|
+
[issues]: https://github.com/simeonwillbanks/busted/issues
|
24
|
+
[pr]: https://help.github.com/articles/using-pull-requests
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Simeon F. Willbanks
|
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,85 @@
|
|
1
|
+
# Busted
|
2
|
+
|
3
|
+
***Requires MRI Ruby 2.1.0dev***
|
4
|
+
|
5
|
+
Find code that busts the Ruby cache.
|
6
|
+
|
7
|
+
- Report when code invalidates Ruby's internal cache
|
8
|
+
- Uses [RubyVM.stat](https://github.com/ruby/ruby/commit/cc1063092b366a0a8449528ab6bf67a72f5ce027)
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
*Any Cache*
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
Busted.cache? do
|
16
|
+
class Pizza
|
17
|
+
end
|
18
|
+
end
|
19
|
+
#=> true
|
20
|
+
```
|
21
|
+
|
22
|
+
*Method Cache*
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
Busted.method_cache? do
|
26
|
+
def pizza
|
27
|
+
end
|
28
|
+
end
|
29
|
+
#=> true
|
30
|
+
```
|
31
|
+
|
32
|
+
*Constant Cache*
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
Busted.constant_cache? do
|
36
|
+
PIZZA = "pizza"
|
37
|
+
end
|
38
|
+
#=> true
|
39
|
+
```
|
40
|
+
|
41
|
+
*Class Cache*
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
Busted.class_cache? do
|
45
|
+
class Beer
|
46
|
+
end
|
47
|
+
end
|
48
|
+
#=> true
|
49
|
+
```
|
50
|
+
|
51
|
+
*No Cache Busted*
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
Busted.cache? do
|
55
|
+
beer = "beer"
|
56
|
+
end
|
57
|
+
#=> false
|
58
|
+
```
|
59
|
+
|
60
|
+
## Installation
|
61
|
+
|
62
|
+
***Requires MRI Ruby 2.1.0dev***
|
63
|
+
|
64
|
+
Add this line to your application's Gemfile:
|
65
|
+
|
66
|
+
gem "busted"
|
67
|
+
|
68
|
+
And then execute:
|
69
|
+
|
70
|
+
$ bundle
|
71
|
+
|
72
|
+
Or install it yourself as:
|
73
|
+
|
74
|
+
$ gem install busted
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Check out [this guide](/CONTRIBUTING.md) if you'd like to contribute.
|
79
|
+
|
80
|
+
## License
|
81
|
+
|
82
|
+
This project is licensed under the [MIT License](/LICENSE.txt).
|
83
|
+
|
84
|
+
## Standing On The Shoulders Of Giants
|
85
|
+
A big *thank you* to [Charlie Somerville](https://github.com/charliesome) and [Aman Gupta](https://github.com/tmm1) for helping flesh out `RubyVM.stat` and committing it to Ruby core!
|
data/Rakefile
ADDED
data/busted.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "busted/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "busted"
|
8
|
+
spec.version = Busted::VERSION
|
9
|
+
spec.authors = ["Simeon F. Willbanks"]
|
10
|
+
spec.email = ["sfw@simeonfosterwillbanks.com"]
|
11
|
+
spec.description = %q{Find code that busts the Ruby cache.}
|
12
|
+
spec.summary = <<-DESC
|
13
|
+
MRI Ruby defines RubyVM.stat which accesses internal cache counters.
|
14
|
+
Busted reports when code increments these counters thereby busting the cache.
|
15
|
+
DESC
|
16
|
+
spec.homepage = "https://github.com/simeonwillbanks/busted"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = [".ruby-version", "CONTRIBUTING.md", "Gemfile",
|
20
|
+
"LICENSE.txt", "README.md", "Rakefile",
|
21
|
+
"busted.gemspec", "lib/busted.rb",
|
22
|
+
"lib/busted/version.rb", "test/busted_test.rb",
|
23
|
+
"test/test_helper.rb"]
|
24
|
+
spec.test_files = spec.files.grep(%r{^test/})
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
end
|
data/lib/busted.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "busted/version"
|
2
|
+
|
3
|
+
module Busted
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def cache?(serial = nil, &blk)
|
7
|
+
starting = count serial
|
8
|
+
yield
|
9
|
+
ending = count serial
|
10
|
+
ending > starting
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_cache?(&blk)
|
14
|
+
cache? :method, &blk
|
15
|
+
end
|
16
|
+
|
17
|
+
def constant_cache?(&blk)
|
18
|
+
cache? :constant, &blk
|
19
|
+
end
|
20
|
+
|
21
|
+
def class_cache?(&blk)
|
22
|
+
cache? :class, &blk
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def count(serial)
|
28
|
+
stat = RubyVM.stat
|
29
|
+
case serial
|
30
|
+
when :method
|
31
|
+
stat[:method_serial]
|
32
|
+
when :constant
|
33
|
+
stat[:constant_serial]
|
34
|
+
when :class
|
35
|
+
stat[:class_serial]
|
36
|
+
else
|
37
|
+
stat[:method_serial] + stat[:constant_serial]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/test/busted_test.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class BustedTest < MiniTest::Unit::TestCase
|
4
|
+
def test_responds_to_cache?
|
5
|
+
assert Busted.respond_to? :cache?
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_responds_to_method_cache?
|
9
|
+
assert Busted.respond_to? :method_cache?
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_responds_to_constant_cache?
|
13
|
+
assert Busted.respond_to? :constant_cache?
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_block_required
|
17
|
+
assert_raises LocalJumpError do
|
18
|
+
Busted.cache?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_empty_block
|
23
|
+
refute Busted.cache? { }
|
24
|
+
refute Busted.method_cache? { }
|
25
|
+
refute Busted.constant_cache? { }
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_cache_with_addition
|
29
|
+
refute Busted.cache? { 1 + 1 }
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_method_cache_with_addition
|
33
|
+
refute Busted.method_cache? { 1 + 1 }
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_constant_cache_with_addition
|
37
|
+
refute Busted.constant_cache? { 1 + 1 }
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_class_cache_with_addition
|
41
|
+
refute Busted.class_cache? { 1 + 1 }
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_cache_with_new_constant
|
45
|
+
assert Busted.cache? { self.class.const_set :"FOO", "foo" }
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_method_cache_with_new_constant
|
49
|
+
refute Busted.method_cache? { self.class.const_set :"BAR", "bar" }
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_constant_cache_with_new_constant
|
53
|
+
assert Busted.constant_cache? { self.class.const_set :"BAZ", "baz" }
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_class_cache_with_new_constant
|
57
|
+
refute Busted.class_cache? { self.class.const_set :"BEER", "beer" }
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_cache_with_new_method
|
61
|
+
assert Busted.cache? { Object.class_exec { def foo; end } }
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_method_cache_with_new_method
|
65
|
+
assert Busted.method_cache? { Object.class_exec { def bar; end } }
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_constant_cache_with_new_method
|
69
|
+
refute Busted.constant_cache? { Object.class_exec { def baz; end } }
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_class_cache_with_new_method
|
73
|
+
refute Busted.class_cache? { Object.class_exec { def beer; end } }
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_cache_with_new_class
|
77
|
+
assert Busted.cache? { Object.class_eval %q{class PierRatPorter; end} }
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_method_cache_with_new_class
|
81
|
+
refute Busted.method_cache? { Object.class_eval %q{class MidnightExpression; end} }
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_constant_cache_with_new_class
|
85
|
+
assert Busted.constant_cache? { Object.class_eval %q{class SantasLittleHelper; end} }
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_class_cache_with_new_class
|
89
|
+
assert Busted.class_cache? { Object.class_eval %q{class TStreetWheat; end} }
|
90
|
+
end
|
91
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: busted
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simeon F. Willbanks
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Find code that busts the Ruby cache.
|
42
|
+
email:
|
43
|
+
- sfw@simeonfosterwillbanks.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".ruby-version"
|
49
|
+
- CONTRIBUTING.md
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- busted.gemspec
|
55
|
+
- lib/busted.rb
|
56
|
+
- lib/busted/version.rb
|
57
|
+
- test/busted_test.rb
|
58
|
+
- test/test_helper.rb
|
59
|
+
homepage: https://github.com/simeonwillbanks/busted
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.1.11
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: MRI Ruby defines RubyVM.stat which accesses internal cache counters. Busted
|
83
|
+
reports when code increments these counters thereby busting the cache.
|
84
|
+
test_files:
|
85
|
+
- test/busted_test.rb
|
86
|
+
- test/test_helper.rb
|