clockblock 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.email = ["jack.ross@technekes.com"]
7
7
  gem.description = %q{Enables easy and DRY code timing capabilities.}
8
8
  gem.summary = %q{Wrap your code in a Clock Block to measure execution duration.}
9
- gem.homepage = ""
9
+ gem.homepage = "https://github.com/jackross/clockblock"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -1,3 +1,3 @@
1
1
  module Clockblock
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,43 +1,81 @@
1
1
  require File.expand_path('../../../spec_helper', __FILE__)
2
2
 
3
- describe "extending Clockblock::Timing in a class definition" do
4
- it "wraps an already defined method in a clock block" do
5
-
6
- foo_klass = Class.new do
7
- extend Clockblock::Timing
8
-
9
- def bar
10
- sleep 1
3
+ describe Clockblock::Timing do
4
+ describe "extending Clockblock::Timing in a class definition" do
5
+ let(:ret_val) { 42 }
6
+
7
+ def run_timing_specs(f)
8
+ f.bar(ret_val).must_equal ret_val
9
+ f.clockblock_timers.must_be_kind_of Hash
10
+ f.clockblock_timers.keys.must_include :bar
11
+ f.clockblock_timers[:bar].must_be_instance_of Clockblock::Timer
12
+ end
13
+
14
+ it "wraps an already defined method in a clock block" do
15
+
16
+ foo_klass = Class.new do
17
+ extend Clockblock::Timing
18
+
19
+ def bar(ret_val)
20
+ sleep 0.1; ret_val
21
+ end
22
+ add_timing_to :bar
23
+
11
24
  end
12
- add_timing_to :bar
25
+
26
+ run_timing_specs foo_klass.new
13
27
 
14
28
  end
15
29
 
16
- f = foo_klass.new
17
- f.bar.must_equal 1
18
- f.clockblock_timers.must_be_kind_of Hash
19
- f.clockblock_timers.keys.must_include :bar
20
- f.clockblock_timers[:bar].must_be_instance_of Clockblock::Timer
30
+ it "wraps an undefined method in a clock block" do
31
+
32
+ foo_klass = Class.new do
33
+ extend Clockblock::Timing
34
+ add_timing_to :bar
21
35
 
22
- end
36
+ def bar(ret_val)
37
+ sleep 0.1; ret_val
38
+ end
39
+
40
+ end
41
+
42
+ run_timing_specs foo_klass.new
23
43
 
24
- it "wraps an undefined method in a clock block" do
25
-
26
- foo_klass = Class.new do
27
- extend Clockblock::Timing
28
- add_timing_to :bar
44
+ end
45
+
46
+ it "wraps a method defined 'after the fact' in a clock block" do
47
+
48
+ foo_klass = Class.new do
49
+ extend Clockblock::Timing
50
+ add_timing_to :bar
29
51
 
30
- def bar
31
- sleep 1
32
52
  end
33
53
 
54
+ foo_klass.class_eval do
55
+ def bar(ret_val)
56
+ sleep 0.1; ret_val
57
+ end
58
+ end
59
+
60
+ run_timing_specs foo_klass.new
61
+
34
62
  end
35
63
 
36
- f = foo_klass.new
37
- f.bar.must_equal 1
38
- f.clockblock_timers.must_be_kind_of Hash
39
- f.clockblock_timers.keys.must_include :bar
40
- f.clockblock_timers[:bar].must_be_instance_of Clockblock::Timer
64
+ it "class can be extended 'after the fact' and still wrap a method defined in a clock block" do
65
+
66
+ foo_klass = Class.new do
67
+ def bar(ret_val)
68
+ sleep 0.1; ret_val
69
+ end
70
+ end
71
+
72
+ foo_klass.class_eval do
73
+ extend Clockblock::Timing
74
+ add_timing_to :bar
75
+ end
41
76
 
77
+ run_timing_specs foo_klass.new
78
+
79
+ end
42
80
  end
43
81
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clockblock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -80,7 +80,7 @@ files:
80
80
  - spec/lib/clockblock/timer_spec.rb
81
81
  - spec/lib/clockblock/timing_spec.rb
82
82
  - spec/spec_helper.rb
83
- homepage: ''
83
+ homepage: https://github.com/jackross/clockblock
84
84
  licenses: []
85
85
  post_install_message:
86
86
  rdoc_options: []