busted 0.2.1 → 0.2.2

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: 4b2f09dd75ef91b3714f55d44f195ef30492d6bb
4
- data.tar.gz: 539f8e9ca781ea35895c26b3a090a70b5c408beb
3
+ metadata.gz: 988c396e54ce313e0340a3cf81235f3572dfb8c5
4
+ data.tar.gz: e714740003083eb282666197a7bf33d9a1e51b09
5
5
  SHA512:
6
- metadata.gz: f222d51d2ade0ad55de451ddc982895dc022443fcdead8c3463ea0da24dbc75f4376260a6942ce5569b2a219ea40e8939530afd32ae3e63f85ae6eb8f3ae46cc
7
- data.tar.gz: 7be3029d528cdc9baac2ae6a3c3b0749e80cff86f7581efbbc884c99beeb38a51472d55b750ad4af960211373d4bc653d8d81cab9ba76b5d26bc52e6213d3e53
6
+ metadata.gz: a94d468be6ace8ceef4f9269fc73aebeee1443d95ad4d2eca88162f7d6ab2fb6737d5c094d39800d3e1bb691d093b0b5f60236c0affc10704cb26609e8525e11
7
+ data.tar.gz: 4c509f67c7f2f1aa1e8362f8e56a9595c1c2f06805c815c2b4387b5be31ef2f6dbce15e7d76b7a267ba1f61b6c475b936722da11edda361cff94635105bd13e1
data/busted.gemspec CHANGED
@@ -17,6 +17,8 @@ Gem::Specification.new do |spec|
17
17
  spec.homepage = "https://github.com/simeonwillbanks/busted"
18
18
  spec.license = "MIT"
19
19
 
20
+ spec.required_ruby_version = ">= 2.1.0"
21
+
20
22
  spec.files = %w(
21
23
  .ruby-version
22
24
  CONTRIBUTING.md
@@ -34,10 +36,12 @@ Gem::Specification.new do |spec|
34
36
  lib/busted/profiler.rb
35
37
  lib/busted/profiler/default.rb
36
38
  lib/busted/profiler/sandwich.rb
39
+ lib/busted/stack.rb
37
40
  lib/busted/traceable.rb
38
41
  lib/busted/tracer.rb
39
42
  lib/busted/version.rb
40
43
  test/busted/current_process_test.rb
44
+ test/busted/stack_test.rb
41
45
  test/busted_test.rb
42
46
  test/test_helper.rb
43
47
  )
@@ -5,7 +5,7 @@ module Busted
5
5
  attr_writer :report
6
6
 
7
7
  def start_counter
8
- @counter = Counter.new
8
+ @counter ||= Counter.new
9
9
 
10
10
  counter.start
11
11
  end
@@ -1,15 +1,24 @@
1
+ require "busted/stack"
2
+
1
3
  module Busted
2
4
  class Counter
3
5
 
6
+ def initialize(stack = Stack.new)
7
+ @stack = stack
8
+ end
9
+
4
10
  def start
5
- @started = counts
11
+ stack.started = counts
6
12
  end
7
13
 
8
14
  def finish
9
- @finished = counts
15
+ stack.finished = counts
10
16
  end
11
17
 
12
18
  def report
19
+ started = stack.started
20
+ finished = stack.finished
21
+
13
22
  [:method, :constant].each_with_object({}) do |counter, result|
14
23
  result[counter] = finished[counter] - started[counter]
15
24
  end
@@ -17,7 +26,7 @@ module Busted
17
26
 
18
27
  private
19
28
 
20
- attr_reader :started, :finished
29
+ attr_reader :stack
21
30
 
22
31
  def counts
23
32
  stat = RubyVM.stat
@@ -47,12 +47,13 @@ module Busted
47
47
  @report = {}
48
48
  start_tracer
49
49
  start_counter
50
+ true
50
51
  end
51
52
 
52
53
  def finish
53
54
  finish_counter
54
55
  finish_tracer
55
- report
56
+ report.dup
56
57
  end
57
58
  end
58
59
  end
@@ -0,0 +1,24 @@
1
+ module Busted
2
+ class Stack
3
+ def initialize
4
+ @started = []
5
+ @finished = []
6
+ end
7
+
8
+ def started
9
+ @started.pop
10
+ end
11
+
12
+ def started=(element)
13
+ @started.push element
14
+ end
15
+
16
+ def finished
17
+ @finished.pop
18
+ end
19
+
20
+ def finished=(element)
21
+ @finished.push element
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Busted
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -0,0 +1,23 @@
1
+ require "test_helper"
2
+
3
+ class Busted::StackTest < MiniTest::Unit::TestCase
4
+ def test_lifo_with_one_set_of_counts
5
+ stack = Busted::Stack.new
6
+ stack.started = 1
7
+ stack.finished = 1
8
+ assert_equal 1, stack.started
9
+ assert_equal 1, stack.finished
10
+ end
11
+
12
+ def test_lifo_with_three_sets_of_counts
13
+ stack = Busted::Stack.new
14
+ stack.started = 1
15
+ stack.started = 2
16
+ stack.started = 3
17
+ stack.finished = 1
18
+ stack.finished = 2
19
+ stack.finished = 3
20
+ assert_equal 3, stack.started
21
+ assert_equal 3, stack.finished
22
+ end
23
+ end
data/test/busted_test.rb CHANGED
@@ -231,6 +231,51 @@ class BustedTest < MiniTest::Unit::TestCase
231
231
  assert Busted.constant_cache? { Object.class_eval "class SantasLittleHelper; end" }
232
232
  end
233
233
 
234
+ def test_nesting_run
235
+ outer_report = {}
236
+ inner_report = {}
237
+
238
+ outer_report = Busted.run do
239
+
240
+ Object.class_eval "class CarlsbadChronic; end"
241
+
242
+ inner_report = Busted.run do
243
+
244
+ Object.class_eval "class SharkBite; end"
245
+ end
246
+ end
247
+
248
+ assert_equal({invalidations:{method:0,constant:1}}, inner_report)
249
+ assert_equal({invalidations:{method:0,constant:2}}, outer_report)
250
+ end
251
+
252
+ def test_nesting_start_finish
253
+ outer_report = {}
254
+ inner_report = {}
255
+
256
+ Busted.start
257
+
258
+ Object.class_eval "class ExtraCheese; end"
259
+
260
+ Busted.start
261
+
262
+ Object.class_eval "class ExtraExtraCheese; end"
263
+
264
+ inner_report = Busted.finish
265
+
266
+ Object.class_eval "class TooMuchCheese; end"
267
+
268
+ outer_report = Busted.finish
269
+
270
+ assert_equal({invalidations:{method:0,constant:1}}, inner_report)
271
+ assert_equal({invalidations:{method:0,constant:3}}, outer_report)
272
+ end
273
+
274
+ def test_start_return_value
275
+ assert_equal true, Busted.start
276
+ Busted.finish
277
+ end
278
+
234
279
  if Busted::Tracer.exists? && Busted::CurrentProcess.privileged?
235
280
 
236
281
  def test_cache_invalidations_and_traces_with_new_method
@@ -239,7 +284,7 @@ class BustedTest < MiniTest::Unit::TestCase
239
284
  assert_equal 0, report[:invalidations][:constant]
240
285
  assert_equal "global", report[:traces][:method][0][:class]
241
286
  assert_match /test\/busted_test.rb\z/, report[:traces][:method][0][:sourcefile]
242
- assert_equal "237", report[:traces][:method][0][:lineno]
287
+ assert_equal "#{__LINE__ - 5}", report[:traces][:method][0][:lineno]
243
288
  end
244
289
 
245
290
  def test_start_finish_and_traces_with_new_method
@@ -250,7 +295,7 @@ class BustedTest < MiniTest::Unit::TestCase
250
295
  assert_equal 0, report[:invalidations][:constant]
251
296
  assert_equal "global", report[:traces][:method][0][:class]
252
297
  assert_match /test\/busted_test.rb\z/, report[:traces][:method][0][:sourcefile]
253
- assert_equal "247", report[:traces][:method][0][:lineno]
298
+ assert_equal "#{__LINE__ - 6}", report[:traces][:method][0][:lineno]
254
299
  end
255
300
  end
256
301
 
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.2.1
4
+ version: 0.2.2
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-26 00:00:00.000000000 Z
11
+ date: 2014-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,10 +61,12 @@ files:
61
61
  - lib/busted/profiler.rb
62
62
  - lib/busted/profiler/default.rb
63
63
  - lib/busted/profiler/sandwich.rb
64
+ - lib/busted/stack.rb
64
65
  - lib/busted/traceable.rb
65
66
  - lib/busted/tracer.rb
66
67
  - lib/busted/version.rb
67
68
  - test/busted/current_process_test.rb
69
+ - test/busted/stack_test.rb
68
70
  - test/busted_test.rb
69
71
  - test/test_helper.rb
70
72
  homepage: https://github.com/simeonwillbanks/busted
@@ -79,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
81
  requirements:
80
82
  - - ">="
81
83
  - !ruby/object:Gem::Version
82
- version: '0'
84
+ version: 2.1.0
83
85
  required_rubygems_version: !ruby/object:Gem::Requirement
84
86
  requirements:
85
87
  - - ">="
@@ -95,5 +97,6 @@ summary: MRI Ruby defines RubyVM.stat which accesses internal cache counters. Wh
95
97
  when code increments these counters.
96
98
  test_files:
97
99
  - test/busted/current_process_test.rb
100
+ - test/busted/stack_test.rb
98
101
  - test/busted_test.rb
99
102
  - test/test_helper.rb