allotment 1.0.3 → 1.0.4

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: e6417cf65f6cb61d3ea29b4270ad1c98e66d4945
4
- data.tar.gz: 9948aa7f2e371bc100081451ce46607db0c09d69
3
+ metadata.gz: 260e997e18de045d11302464320c034d157543ea
4
+ data.tar.gz: d07b300e2acb0bdb7d9441117db692d5e3567cc3
5
5
  SHA512:
6
- metadata.gz: 2b285e0947b4a97ef2578cfd9706e17f2f480b65b3436d0e8c8593c921b4b34cedfc42f9b014ad6c451c1bc2d0b0ec69cb5156327686133c02ab075c5c07a6f6
7
- data.tar.gz: 53f7a0b502ac4d7ee3b5371893c2785c2fdd85e58b10f124338942d657d0f1675d3cfe92e0290f5074b615330f4ec351618a2be7f6a51488fae331832f1c3677
6
+ metadata.gz: 8cbe37969369a29dcc2b000c42842c043c7d97996aba626b03861f96150d1a58f704ec475d125f66f6165348a6cd5e6e4adbf7809c2e87b92d266b623b60130d
7
+ data.tar.gz: bbb47b9c27e82b8b1696f9b20766751daf8ba545e6b6714b9283a40e1ff7bebc3f193531ca4554461b5bfe94eb5e5af0ba62eba1f91599a67a1d4fbbf2e14541
data/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (C) 2013 Ben Slaughter
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -115,27 +115,3 @@ result = Allotment.results["my_recording"].average
115
115
 
116
116
  TODO
117
117
 
118
- ## Release Notes
119
- ### Version 1.0.0
120
- ###### Major: Inital release version.
121
- * Allotment has the ablility to record blocks and procs, and to record from two separate points within the code.
122
- * Stopwatch has been completed and can start, stop, split, lap and restart.
123
- * There is an extention of Array for an average.
124
- * There is Cucumber support, a cucumber file has been included that will record scenario and test time.
125
-
126
- ### Version 1.0.1
127
- ###### Patch: Added instance methods
128
- * Added instance methods so that the module can be included into a class and allotment does not need to be called every time.
129
- * Cleaned up stopwatch so that it had lap and split
130
-
131
- ## Version 1.0.2
132
- ###### Patch: Results returned as Hashie::Mash
133
- * results methods now return results as a Hashie::Mash
134
-
135
- ## Planned Releases
136
- ### Version 1.1.0
137
- ###### Minor: Improvements to recording events and stopwatch management
138
- * Rescue within an event to ensure that the timing is stopped in the event of a failure
139
- * Complete the readme with updated information on using stopwatches
140
- * A complete record of all spawned stopwatches
141
-
data/allotment.gemspec CHANGED
@@ -15,10 +15,12 @@ Gem::Specification.new do |spec|
15
15
  spec.email = 'b.p.slaughter@gmail.com'
16
16
 
17
17
  spec.add_development_dependency 'rspec'
18
+ spec.add_development_dependency 'pry'
18
19
  spec.add_development_dependency 'coveralls'
19
20
  spec.add_runtime_dependency 'hashie'
21
+ spec.add_runtime_dependency 'hooks'
20
22
 
21
- spec.files = ['README.md', 'allotment.gemspec']
23
+ spec.files = ['README.md', 'LICENSE.md', 'allotment.gemspec']
22
24
  spec.files += Dir.glob("lib/**/*.rb")
23
25
  spec.files += Dir.glob("spec/**/*")
24
26
  spec.test_files = Dir.glob("spec/**/*")
@@ -0,0 +1,23 @@
1
+ class Allotment
2
+ module Methods
3
+ def record_event name = 'unnamed', &block
4
+ Allotment.record_event name, &block
5
+ end
6
+
7
+ def start_recording name = 'unnamed'
8
+ Allotment.start_recording name
9
+ end
10
+
11
+ def stop_recording name
12
+ Allotment.stop_recording name
13
+ end
14
+
15
+ def results
16
+ Allotment.results
17
+ end
18
+
19
+ def results_string
20
+ Allotment.results_string
21
+ end
22
+ end
23
+ end
@@ -1,4 +1,4 @@
1
- module Allotment
1
+ class Allotment
2
2
  class Stopwatch
3
3
  attr_reader :name, :status
4
4
 
@@ -1,4 +1,4 @@
1
- module Allotment
2
- VERSION = "1.0.3".freeze
3
- DATE = "2013-08-29".freeze
1
+ class Allotment
2
+ VERSION = "1.0.4".freeze
3
+ DATE = "2013-09-02".freeze
4
4
  end
data/lib/allotment.rb CHANGED
@@ -1,17 +1,27 @@
1
1
  require 'allotment/array'
2
2
  require 'allotment/stopwatch'
3
+
3
4
  require 'json'
4
5
  require 'hashie'
6
+ require 'hooks'
7
+
8
+ class Allotment
9
+ include Hooks
10
+ define_hooks :before, :after
5
11
 
6
- module Allotment
7
12
  class << self
8
13
  def record_event name = 'unnamed', &block
9
14
  start_recording name
10
- yield
11
- stop_recording name
15
+ begin
16
+ yield
17
+ ensure
18
+ time = stop_recording name
19
+ end
20
+ return time
12
21
  end
13
22
 
14
23
  def start_recording name = 'unnamed'
24
+ run_hook :before
15
25
  @watches ||= Hashie::Mash.new
16
26
  @watches[name] = Stopwatch.new name
17
27
  end
@@ -19,12 +29,12 @@ module Allotment
19
29
  def stop_recording name
20
30
  watch = @watches.delete(name) { |n| raise NameError, "No recording:" + n }
21
31
  result = watch.stop
32
+ run_hook :after
22
33
 
23
34
  # Dealing with the results
24
35
  @results ||= Hashie::Mash.new
25
36
  @results[name] ||= Array.new
26
37
  @results[name] << result
27
-
28
38
  return result
29
39
  end
30
40
 
@@ -36,24 +46,4 @@ module Allotment
36
46
  JSON.pretty_generate @results
37
47
  end
38
48
  end
39
-
40
- def record_event name = 'unnamed', &block
41
- Allotment.record_event name, &block
42
- end
43
-
44
- def start_recording name = 'unnamed'
45
- Allotment.start_recording name
46
- end
47
-
48
- def stop_recording name
49
- Allotment.stop_recording name
50
- end
51
-
52
- def results
53
- Allotment.results
54
- end
55
-
56
- def results_string
57
- Allotment.results_string
58
- end
59
49
  end
@@ -1,12 +1,8 @@
1
1
  require 'helper'
2
2
 
3
- class DummyClass
4
- include Allotment
5
- end
6
-
7
3
  describe Allotment do
8
- it "is a module" do
9
- Allotment.class.should eq Module
4
+ it "is a class" do
5
+ Allotment.class.should eq Class
10
6
  end
11
7
 
12
8
  describe ".record_event" do
@@ -29,31 +25,10 @@ describe Allotment do
29
25
  result = Allotment.record_event('my_recording 0.4') { sleep 0.01 }
30
26
  result.round(2).should eq 0.01
31
27
  end
32
- end
33
-
34
- describe "#record_event" do
35
- before(:each) do
36
- @dummy_class = DummyClass.new
37
- end
38
-
39
- it "records the time for the block" do
40
- @dummy_class.record_event('my_recording 0.1') { sleep 0.01 }
41
- end
42
-
43
- it "records the time for the proc" do
44
- @dummy_class.record_event 'my_recording 0.2' do
45
- sleep 0.01
46
- end
47
- end
48
28
 
49
- it "returns a float" do
50
- result = @dummy_class.record_event('my_recording 0.3') { sleep 0.01 }
51
- result.class.should eq Float
52
- end
53
-
54
- it "returns the execute time of the block" do
55
- result = @dummy_class.record_event('my_recording 0.4') { sleep 0.01 }
56
- result.round(2).should eq 0.01
29
+ it "returns still records the performance upon error" do
30
+ expect { Allotment.record_event('failed_recording') { sleep 0.01; raise 'error' } }.to raise_error RuntimeError, "error"
31
+ Allotment.results['failed_recording'].first.round(2).should eq 0.01
57
32
  end
58
33
  end
59
34
 
@@ -79,32 +54,6 @@ describe Allotment do
79
54
  end
80
55
  end
81
56
 
82
- describe "#start_recording" do
83
- before(:each) do
84
- @dummy_class = DummyClass.new
85
- end
86
-
87
- it "returns a stopwatch instance" do
88
- result = @dummy_class.start_recording
89
- result.class.should eq Allotment::Stopwatch
90
- end
91
-
92
- it "returns an unnamed stopwatch if no name given" do
93
- result = @dummy_class.start_recording
94
- result.name.should eq 'unnamed'
95
- end
96
-
97
- it "returns a stopwatch with the given name" do
98
- result = @dummy_class.start_recording 'my_recording'
99
- result.name.should eq 'my_recording'
100
- end
101
-
102
- it "returns a stopwatch that is 'running'" do
103
- result = @dummy_class.start_recording
104
- result.status.should eq 'running'
105
- end
106
- end
107
-
108
57
  describe ".stop_recording" do
109
58
  it "returns a float" do
110
59
  Allotment.start_recording 'my_recording1'
@@ -125,27 +74,29 @@ describe Allotment do
125
74
  end
126
75
  end
127
76
 
128
- describe "#stop_recording" do
129
- before(:each) do
130
- @dummy_class = DummyClass.new
77
+ describe ".before" do
78
+ it "adds a hook to the before hooks array" do
79
+ hooks = Allotment.before { nil }
80
+ Allotment._hooks[:before].should eq hooks
131
81
  end
132
82
 
133
- it "returns a float" do
134
- @dummy_class.start_recording 'my_recording1'
135
- sleep 0.01
136
- result = @dummy_class.stop_recording 'my_recording1'
137
- result.class.should eq Float
83
+ it "runs the hook before the performance recording" do
84
+ Allotment.before { @before = Time.now.to_f }
85
+ Allotment.record_event('before') { @record = Time.now.to_f }
86
+ @record.should be > Allotment.instance_variable_get("@before")
138
87
  end
88
+ end
139
89
 
140
- it "returns the execute time of the code" do
141
- @dummy_class.start_recording 'my_recording2'
142
- sleep 0.01
143
- result = @dummy_class.stop_recording 'my_recording2'
144
- result.round(2).should eq 0.01
90
+ describe ".after" do
91
+ it "adds a hook to the after hooks array" do
92
+ hooks = Allotment.after { nil }
93
+ Allotment._hooks[:after].should eq hooks
145
94
  end
146
95
 
147
- it "raises an error if the recording does not exist" do
148
- expect { @dummy_class.stop_recording 'my_recording3' }.to raise_error NameError, "No recording:my_recording3"
96
+ it "runs the hook after the performance recording" do
97
+ Allotment.after { @after = Time.now.to_f }
98
+ Allotment.record_event('after') { @record = Time.now.to_f }
99
+ @record.should be < Allotment.instance_variable_get("@after")
149
100
  end
150
101
  end
151
102
 
@@ -173,34 +124,6 @@ describe Allotment do
173
124
  end
174
125
  end
175
126
 
176
- describe "#results" do
177
- before(:each) do
178
- @dummy_class = DummyClass.new
179
- end
180
-
181
- it "returns a hash" do
182
- @dummy_class.record_event('my_recording4') { sleep 0.01 }
183
- @dummy_class.results.class.should eq Hashie::Mash
184
- end
185
-
186
- it "returns a hash with the event in" do
187
- @dummy_class.record_event('my_recording5') { sleep 0.01 }
188
- @dummy_class.results.should include('my_recording5')
189
- end
190
-
191
- it "stores the result under the event" do
192
- @dummy_class.record_event('my_recording6') { sleep 0.01 }
193
- @dummy_class.results['my_recording6'][0].round(2).should eq 0.01
194
- end
195
-
196
- it "stores each result of each event" do
197
- @dummy_class.record_event('my_recording7') { sleep 0.01 }
198
- @dummy_class.record_event('my_recording7') { sleep 0.02 }
199
- @dummy_class.results['my_recording7'][0].round(2).should eq 0.01
200
- @dummy_class.results['my_recording7'][1].round(2).should eq 0.02
201
- end
202
- end
203
-
204
127
  describe ".results_string" do
205
128
  it "returns a string" do
206
129
  Allotment.record_event('my_recording8') { sleep 0.01 }
@@ -209,25 +132,8 @@ describe Allotment do
209
132
 
210
133
  it "returns a string with the event in" do
211
134
  Allotment.record_event('my_recording9') { sleep 0.03 }
212
- Allotment.results_string.should include('my_recording9')
213
- Allotment.results_string.should include('0.03')
214
- end
215
- end
216
-
217
- describe "#results_string" do
218
- before(:each) do
219
- @dummy_class = DummyClass.new
220
- end
221
-
222
- it "returns a string" do
223
- @dummy_class.record_event('my_recording8') { sleep 0.01 }
224
- @dummy_class.results_string.class.should eq String
225
- end
226
-
227
- it "returns a string with the event in" do
228
- @dummy_class.record_event('my_recording9') { sleep 0.03 }
229
- @dummy_class.results_string.should include('my_recording9')
230
- @dummy_class.results_string.should include('0.03')
135
+ Allotment.results_string.should include 'my_recording9'
136
+ Allotment.results_string.should include '0.03'
231
137
  end
232
138
  end
233
139
  end
data/spec/helper.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  require 'coveralls'
2
- Coveralls.wear!
2
+ require 'pry'
3
3
 
4
4
  require 'allotment'
5
+ require 'allotment/methods'
6
+
7
+ Coveralls.wear!
5
8
 
6
9
  RSpec.configure do |config|
7
10
  config.color_enabled = true
@@ -0,0 +1,130 @@
1
+ class DummyClass
2
+ include Allotment::Methods
3
+ end
4
+
5
+ describe Allotment::Methods do
6
+ it "is a module" do
7
+ Allotment::Methods.class.should eq Module
8
+ end
9
+
10
+ describe "#record_event" do
11
+ before(:each) do
12
+ @dummy_class = DummyClass.new
13
+ end
14
+
15
+ it "records the time for the block" do
16
+ @dummy_class.record_event('my_recording 0.1') { sleep 0.01 }
17
+ end
18
+
19
+ it "records the time for the proc" do
20
+ @dummy_class.record_event 'my_recording 0.2' do
21
+ sleep 0.01
22
+ end
23
+ end
24
+
25
+ it "returns a float" do
26
+ result = @dummy_class.record_event('my_recording 0.3') { sleep 0.01 }
27
+ result.class.should eq Float
28
+ end
29
+
30
+ it "returns the execute time of the block" do
31
+ result = @dummy_class.record_event('my_recording 0.4') { sleep 0.01 }
32
+ result.round(2).should eq 0.01
33
+ end
34
+ end
35
+
36
+ describe "#start_recording" do
37
+ before(:each) do
38
+ @dummy_class = DummyClass.new
39
+ end
40
+
41
+ it "returns a stopwatch instance" do
42
+ result = @dummy_class.start_recording
43
+ result.class.should eq Allotment::Stopwatch
44
+ end
45
+
46
+ it "returns an unnamed stopwatch if no name given" do
47
+ result = @dummy_class.start_recording
48
+ result.name.should eq 'unnamed'
49
+ end
50
+
51
+ it "returns a stopwatch with the given name" do
52
+ result = @dummy_class.start_recording 'my_recording'
53
+ result.name.should eq 'my_recording'
54
+ end
55
+
56
+ it "returns a stopwatch that is 'running'" do
57
+ result = @dummy_class.start_recording
58
+ result.status.should eq 'running'
59
+ end
60
+ end
61
+
62
+ describe "#stop_recording" do
63
+ before(:each) do
64
+ @dummy_class = DummyClass.new
65
+ end
66
+
67
+ it "returns a float" do
68
+ @dummy_class.start_recording 'my_recording1'
69
+ sleep 0.01
70
+ result = @dummy_class.stop_recording 'my_recording1'
71
+ result.class.should eq Float
72
+ end
73
+
74
+ it "returns the execute time of the code" do
75
+ @dummy_class.start_recording 'my_recording2'
76
+ sleep 0.01
77
+ result = @dummy_class.stop_recording 'my_recording2'
78
+ result.round(2).should eq 0.01
79
+ end
80
+
81
+ it "raises an error if the recording does not exist" do
82
+ expect { @dummy_class.stop_recording 'my_recording3' }.to raise_error NameError, "No recording:my_recording3"
83
+ end
84
+ end
85
+
86
+ describe "#results" do
87
+ before(:each) do
88
+ @dummy_class = DummyClass.new
89
+ end
90
+
91
+ it "returns a hash" do
92
+ @dummy_class.record_event('my_recording4') { sleep 0.01 }
93
+ @dummy_class.results.class.should eq Hashie::Mash
94
+ end
95
+
96
+ it "returns a hash with the event in" do
97
+ @dummy_class.record_event('my_recording5') { sleep 0.01 }
98
+ @dummy_class.results.should include('my_recording5')
99
+ end
100
+
101
+ it "stores the result under the event" do
102
+ @dummy_class.record_event('my_recording6') { sleep 0.01 }
103
+ @dummy_class.results['my_recording6'][0].round(2).should eq 0.01
104
+ end
105
+
106
+ it "stores each result of each event" do
107
+ @dummy_class.record_event('my_recording7') { sleep 0.01 }
108
+ @dummy_class.record_event('my_recording7') { sleep 0.02 }
109
+ @dummy_class.results['my_recording7'][0].round(2).should eq 0.01
110
+ @dummy_class.results['my_recording7'][1].round(2).should eq 0.02
111
+ end
112
+ end
113
+
114
+ describe "#results_string" do
115
+ before(:each) do
116
+ @dummy_class = DummyClass.new
117
+ end
118
+
119
+ it "returns a string" do
120
+ @dummy_class.record_event('my_recording8') { sleep 0.01 }
121
+ @dummy_class.results_string.class.should eq String
122
+ end
123
+
124
+ it "returns a string with the event in" do
125
+ @dummy_class.record_event('my_recording9') { sleep 0.03 }
126
+ @dummy_class.results_string.should include('my_recording9')
127
+ @dummy_class.results_string.should include('0.03')
128
+ end
129
+ end
130
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allotment
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Slaughter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-29 00:00:00.000000000 Z
11
+ date: 2013-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
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'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: coveralls
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - '>='
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: hooks
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: Simple performance recordings of blocks, procs or point to point
56
84
  email: b.p.slaughter@gmail.com
57
85
  executables: []
@@ -59,15 +87,18 @@ extensions: []
59
87
  extra_rdoc_files: []
60
88
  files:
61
89
  - README.md
90
+ - LICENSE.md
62
91
  - allotment.gemspec
63
92
  - lib/allotment/array.rb
64
93
  - lib/allotment/cucumber.rb
94
+ - lib/allotment/methods.rb
65
95
  - lib/allotment/stopwatch.rb
66
96
  - lib/allotment/version.rb
67
97
  - lib/allotment.rb
68
98
  - spec/allotment_spec.rb
69
99
  - spec/helper.rb
70
100
  - spec/stopwatch/array_spec.rb
101
+ - spec/stopwatch/methods_spec.rb
71
102
  - spec/stopwatch/stopwatch_spec.rb
72
103
  homepage: http://benslaughter.github.io/allotment/
73
104
  licenses:
@@ -97,5 +128,5 @@ test_files:
97
128
  - spec/allotment_spec.rb
98
129
  - spec/helper.rb
99
130
  - spec/stopwatch/array_spec.rb
131
+ - spec/stopwatch/methods_spec.rb
100
132
  - spec/stopwatch/stopwatch_spec.rb
101
- has_rdoc: