busted 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca3f17fb6e19fab0e2e5604ff88570507f8c1224
4
- data.tar.gz: 15884ecda376d2f29feabd868d7d41de6bc25024
3
+ metadata.gz: 798beba5202a28ac6f4267be4c81248596a16dae
4
+ data.tar.gz: a698056e415519ddef76442a3a87c403102e3e05
5
5
  SHA512:
6
- metadata.gz: d76855a302daf921cc84681c5a006872616671aa0ca0eb6e4490ef967c738112191f25a1efcbea25496e5c6d2e4e545ff769bffe85561be84a9c1d1fc33a0625
7
- data.tar.gz: 95305e22d2ad4168d506ca83d501e7cb55a0ab90337c0dbd8a2e1843f8661c1f8adccc83f28570f1f9e07138d4577de05614d440a702f5fab5496def07ae1c38
6
+ metadata.gz: b83f103bf02c10778f518bf10a6628bff8b42e98322a710bf7500ce5755f54f345162390e10c49ff0ced896746cbdda1e06f37e93a2d3bba3a10fb41d4246bb6
7
+ data.tar.gz: 455e19287871c565b23d5d5cf10f4b08c1fb49b37b50846bd8ef6e715be790014ef6d2b39767977b919daaee169671d52fca635eb5f1c3824d0a4a23a915b6cc
data/README.md CHANGED
@@ -26,6 +26,12 @@ Busted.run do
26
26
  end
27
27
  end
28
28
  #=> {:invalidations=>{:method=>0, :constant=>1}}
29
+
30
+ Busted.start
31
+ class Pie
32
+ end
33
+ Busted.finish
34
+ #=> {:invalidations=>{:method=>0, :constant=>1}}
29
35
  ```
30
36
 
31
37
  *Method Cache*
@@ -41,7 +47,19 @@ Busted.method_cache_invalidations do
41
47
  def pizza
42
48
  end
43
49
  end
44
- #=> 3
50
+ #=> 1
51
+
52
+ Busted.run do
53
+ def pie
54
+ end
55
+ end
56
+ #=> {:invalidations=>{:method=>1, :constant=>0}}
57
+
58
+ Busted.start
59
+ def smoothie
60
+ end
61
+ Busted.finish
62
+ #=> {:invalidations=>{:method=>1, :constant=>0}}
45
63
  ```
46
64
 
47
65
  *Constant Cache*
@@ -56,6 +74,16 @@ Busted.constant_cache_invalidations do
56
74
  CHEESE = "cheese"
57
75
  end
58
76
  #=> 1
77
+
78
+ Busted.run do
79
+ PIE = "pumpkin"
80
+ end
81
+ #=> {:invalidations=>{:method=>0, :constant=>1}}
82
+
83
+ Busted.start
84
+ SMOOTHIE = "blueberry"
85
+ Busted.finish
86
+ #=> {:invalidations=>{:method=>0, :constant=>1}}
59
87
  ```
60
88
 
61
89
  *No Cache Busted*
@@ -70,6 +98,11 @@ Busted.run do
70
98
  pizza = "pizza"
71
99
  end
72
100
  #=> {:invalidations=>{:method=>0, :constant=>0}}
101
+
102
+ Busted.start
103
+ pie = "pie"
104
+ Busted.finish
105
+ #=> {:invalidations=>{:method=>0, :constant=>0}}
73
106
  ```
74
107
 
75
108
  ## Advanced Usage
@@ -81,7 +114,8 @@ require "busted"
81
114
  require "pp"
82
115
 
83
116
  report = Busted.run(trace: true) do
84
- def cookie; end
117
+ def cookie
118
+ end
85
119
  end
86
120
  pp report
87
121
  ```
@@ -108,6 +142,25 @@ $ ruby trace.rb
108
142
  {:method=>[{:class=>"global", :sourcefile=>"trace.rb", :lineno=>"5"}]}}
109
143
  ```
110
144
 
145
+ *start_finish_trace.rb*
146
+ ```ruby
147
+ require "busted"
148
+ require "pp"
149
+
150
+ Busted.start trace: true
151
+ def ice_cream
152
+ end
153
+ pp Busted.finish
154
+ ```
155
+
156
+ ```bash
157
+ $ ruby start_finish_trace.rb
158
+ {:invalidations=>{:method=>1, :constant=>0},
159
+ :traces=>
160
+ {:method=>
161
+ [{:class=>"global", :sourcefile=>"start_finish_trace.rb", :lineno=>"5"}]}}
162
+ ```
163
+
111
164
  Busted includes an [example `dtrace` probe](/dtrace/probes/examples/method-cache-clear.d) for use on the command line or an application. See the [probe](/dtrace/probes/examples/method-cache-clear.d) for usage.
112
165
 
113
166
  ## Installation
data/busted.gemspec CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
33
33
  lib/busted/current_process.rb
34
34
  lib/busted/profiler.rb
35
35
  lib/busted/profiler/default.rb
36
+ lib/busted/profiler/sandwich.rb
36
37
  lib/busted/traceable.rb
37
38
  lib/busted/tracer.rb
38
39
  lib/busted/version.rb
@@ -7,6 +7,10 @@ module Busted
7
7
 
8
8
  attr_reader :trace, :block, :report
9
9
 
10
+ def self.run(options = {}, &block)
11
+ new(options, &block).run
12
+ end
13
+
10
14
  def initialize(options = {}, &block)
11
15
  fail LocalJumpError, "no block given" unless block
12
16
 
@@ -0,0 +1,59 @@
1
+ require "singleton"
2
+
3
+ module Busted
4
+ module Profiler
5
+ class Sandwich
6
+
7
+ include Singleton
8
+
9
+ include Busted::Traceable
10
+ include Busted::Countable
11
+
12
+ VALID_ACTIONS = [:start, :finish].freeze
13
+
14
+ attr_accessor :action
15
+ attr_reader :trace, :report
16
+
17
+ def self.run(options = {})
18
+ action = options.fetch :action, false
19
+ trace = options.fetch :trace, false
20
+
21
+ unless VALID_ACTIONS.include? action
22
+ fail ArgumentError, "profiler requires start or finish action"
23
+ end
24
+
25
+ sandwich = instance
26
+
27
+ sandwich.action = action
28
+ sandwich.trace = trace
29
+ sandwich.run
30
+ end
31
+
32
+ def run
33
+ send action
34
+ end
35
+
36
+ def trace=(trace)
37
+ @trace = trace if start?
38
+ end
39
+
40
+ private
41
+
42
+ def start?
43
+ action == :start
44
+ end
45
+
46
+ def start
47
+ @report = {}
48
+ start_tracer
49
+ start_counter
50
+ end
51
+
52
+ def finish
53
+ finish_counter
54
+ finish_tracer
55
+ report
56
+ end
57
+ end
58
+ end
59
+ end
@@ -2,14 +2,16 @@ require "busted/counter"
2
2
  require "busted/countable"
3
3
  require "busted/tracer"
4
4
  require "busted/traceable"
5
- require "busted/profiler/default"
6
5
 
7
6
  module Busted
8
7
  module Profiler
9
8
  extend self
10
9
 
10
+ autoload :Default, "busted/profiler/default"
11
+ autoload :Sandwich, "busted/profiler/sandwich"
12
+
11
13
  def run(options, &block)
12
- klass(options.fetch :profiler, :default).new(options, &block).run
14
+ klass(options.fetch :profiler, :default).run(options, &block)
13
15
  end
14
16
 
15
17
  private
@@ -1,3 +1,3 @@
1
1
  module Busted
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/busted.rb CHANGED
@@ -7,6 +7,14 @@ module Busted
7
7
  Profiler.run options, &block
8
8
  end
9
9
 
10
+ def start(options = {})
11
+ Profiler.run({ profiler: :sandwich, action: :start }.merge options)
12
+ end
13
+
14
+ def finish(options = {})
15
+ Profiler.run({ profiler: :sandwich, action: :finish }.merge options)
16
+ end
17
+
10
18
  def method_cache_invalidations(&block)
11
19
  run(&block)[:invalidations][:method]
12
20
  end
data/test/busted_test.rb CHANGED
@@ -8,6 +8,13 @@ class BustedTest < MiniTest::Unit::TestCase
8
8
  assert_equal "profiler `pizza' does not exist", error.message
9
9
  end
10
10
 
11
+ def test_invalid_profiler_action_exception
12
+ error = assert_raises ArgumentError do
13
+ Busted.start profiler: :sandwich, action: :pizza
14
+ end
15
+ assert_equal "profiler requires start or finish action", error.message
16
+ end
17
+
11
18
  def test_cache_invalidations_requires_block
12
19
  assert_raises LocalJumpError do
13
20
  Busted.run
@@ -54,6 +61,14 @@ class BustedTest < MiniTest::Unit::TestCase
54
61
  assert_equal 0, Busted.constant_cache_invalidations { 1 + 1 }
55
62
  end
56
63
 
64
+ def test_start_finish_with_addition
65
+ Busted.start
66
+ 1 + 1
67
+ report = Busted.finish
68
+ assert_equal 0, report[:invalidations][:method]
69
+ assert_equal 0, report[:invalidations][:constant]
70
+ end
71
+
57
72
  def test_cache_invalidations_with_new_constant
58
73
  report = Busted.run { self.class.const_set :"CHEESE", "cheese" }
59
74
  assert_equal 0, report[:invalidations][:method]
@@ -74,6 +89,14 @@ class BustedTest < MiniTest::Unit::TestCase
74
89
  assert_equal 1, invalidations
75
90
  end
76
91
 
92
+ def test_start_finish_with_new_constant
93
+ Busted.start
94
+ self.class.const_set :"PEPPERONI", "pepperoni"
95
+ report = Busted.finish
96
+ assert_equal 0, report[:invalidations][:method]
97
+ assert_equal 1, report[:invalidations][:constant]
98
+ end
99
+
77
100
  def test_cache_invalidations_with_new_method
78
101
  report = Busted.run { Object.class_exec { def cheese; end } }
79
102
  assert_equal 1, report[:invalidations][:method]
@@ -94,6 +117,14 @@ class BustedTest < MiniTest::Unit::TestCase
94
117
  assert_equal 0, invalidations
95
118
  end
96
119
 
120
+ def test_start_finish_with_new_method
121
+ Busted.start
122
+ Object.class_exec { def pepperoni; end }
123
+ report = Busted.finish
124
+ assert_equal 1, report[:invalidations][:method]
125
+ assert_equal 0, report[:invalidations][:constant]
126
+ end
127
+
97
128
  def test_cache_invalidations_with_new_class
98
129
  report = Busted.run { Object.class_eval "class ThreeCheese; end" }
99
130
  assert_equal 0, report[:invalidations][:method]
@@ -114,6 +145,14 @@ class BustedTest < MiniTest::Unit::TestCase
114
145
  assert_equal 1, invalidations
115
146
  end
116
147
 
148
+ def test_start_finish_with_new_class
149
+ Busted.start
150
+ Object.class_eval "class Pepperoni; end"
151
+ report = Busted.finish
152
+ assert_equal 0, report[:invalidations][:method]
153
+ assert_equal 1, report[:invalidations][:constant]
154
+ end
155
+
117
156
  def test_cache_predicate_requires_block
118
157
  assert_raises LocalJumpError do
119
158
  Busted.cache?
@@ -200,7 +239,18 @@ class BustedTest < MiniTest::Unit::TestCase
200
239
  assert_equal 0, report[:invalidations][:constant]
201
240
  assert_equal "global", report[:traces][:method][0][:class]
202
241
  assert_match /test\/busted_test.rb\z/, report[:traces][:method][0][:sourcefile]
203
- assert_equal "198", report[:traces][:method][0][:lineno]
242
+ assert_equal "237", report[:traces][:method][0][:lineno]
243
+ end
244
+
245
+ def test_start_finish_and_traces_with_new_method
246
+ Busted.start trace: true
247
+ Object.class_exec { def candy; end }
248
+ report = Busted.finish
249
+ assert_equal 1, report[:invalidations][:method]
250
+ assert_equal 0, report[:invalidations][:constant]
251
+ assert_equal "global", report[:traces][:method][0][:class]
252
+ assert_match /test\/busted_test.rb\z/, report[:traces][:method][0][:sourcefile]
253
+ assert_equal "247", report[:traces][:method][0][:lineno]
204
254
  end
205
255
  end
206
256
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: busted
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simeon F. Willbanks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-19 00:00:00.000000000 Z
11
+ date: 2013-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,6 +60,7 @@ files:
60
60
  - lib/busted/current_process.rb
61
61
  - lib/busted/profiler.rb
62
62
  - lib/busted/profiler/default.rb
63
+ - lib/busted/profiler/sandwich.rb
63
64
  - lib/busted/traceable.rb
64
65
  - lib/busted/tracer.rb
65
66
  - lib/busted/version.rb