rspec_timer 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/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +2 -0
- data/lib/rspec_timer.rb +65 -0
- data/lib/rspec_timer/version.rb +3 -0
- data/rspec_timer.gemspec +30 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ea80db1b742f822c6042e37dd61b3b0cfc0b7786
|
4
|
+
data.tar.gz: 8a2e05d302c6c3d55b09111215c5db6f2503f65f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: efa539dcad84281c1a370ebe3bb9fded98d1de9e87dcc86ea7b88e36d646686dc7221cfa5e07c28a9f997ee6c8f3b7a137786fde9054f39dd0b42486e99eb4e4
|
7
|
+
data.tar.gz: ab5a668874d08897e01ba35eb87a692f5f18071d59af9fc2241ea165bad5bfe96fbfa1d3dfd9d4efb06280ef9d145f54b3cfff4abdcfd64c6fd05275795da316
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Tom Chapin
|
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,48 @@
|
|
1
|
+
# RspecTimer
|
2
|
+
|
3
|
+
RSpecTimer will track the amount of time each of your tests take to complete,
|
4
|
+
and when it's done, can save the data to a YAML file.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'rspec_timer'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install rspec_timer
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
In your spec_helper.rb file, set up your "around" and "after" hooks like so:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
|
28
|
+
RSpec.configure do |config|
|
29
|
+
|
30
|
+
config.around(:each) do |example|
|
31
|
+
RspecTimer.run_and_measure(example)
|
32
|
+
end
|
33
|
+
|
34
|
+
config.after(:suite) do
|
35
|
+
RspecTimer.save_metrics_to_file(Rails.root.join('rspec_metrics.yml').to_s)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
```
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it ( https://github.com/tomchapin/rspec_timer/fork )
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/rspec_timer.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'rspec_timer/version'
|
2
|
+
require 'singleton'
|
3
|
+
require 'forwardable'
|
4
|
+
require 'digest/md5'
|
5
|
+
|
6
|
+
class RspecTimer
|
7
|
+
include Singleton
|
8
|
+
extend SingleForwardable
|
9
|
+
|
10
|
+
def_delegators :instance, :reset_metrics, :start_measurement, :end_measurement, :metrics, :run_and_measure, :save_metrics_to_file
|
11
|
+
|
12
|
+
attr_reader :metrics
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
reset_metrics
|
16
|
+
end
|
17
|
+
|
18
|
+
def reset_metrics
|
19
|
+
@metrics = {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def start_measurement(example)
|
23
|
+
current_metrics = metrics_for(example)
|
24
|
+
current_metrics[:signature] = signature_for(example)
|
25
|
+
current_metrics[:start_time] = Time.now
|
26
|
+
example
|
27
|
+
end
|
28
|
+
|
29
|
+
def end_measurement(example)
|
30
|
+
current_metrics = metrics_for(example)
|
31
|
+
current_metrics[:end_time] = Time.now
|
32
|
+
current_metrics[:total_time] = current_metrics[:end_time] - current_metrics[:start_time]
|
33
|
+
example
|
34
|
+
end
|
35
|
+
|
36
|
+
def run_and_measure(example)
|
37
|
+
start_measurement(example)
|
38
|
+
example.run
|
39
|
+
end_measurement(example)
|
40
|
+
end
|
41
|
+
|
42
|
+
def save_metrics_to_file(file_name)
|
43
|
+
File.write(file_name, YAML.dump(@metrics))
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def metrics_for(example)
|
49
|
+
@metrics[example_path(example)] ||= {
|
50
|
+
start_time: nil,
|
51
|
+
end_time: nil,
|
52
|
+
total_time: nil,
|
53
|
+
signature: nil
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def signature_for(example)
|
58
|
+
Digest::MD5.hexdigest(example.example.instance_variable_get(:@example_block).source.to_s)
|
59
|
+
end
|
60
|
+
|
61
|
+
def example_path(example)
|
62
|
+
"#{example.metadata[:file_path]}:#{example.metadata[:line_number]}"
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/rspec_timer.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec_timer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec_timer"
|
8
|
+
spec.version = RspecTimer::VERSION
|
9
|
+
spec.authors = ["Tom Chapin"]
|
10
|
+
spec.email = ["tchapin@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Measure how long each of your RSpec tests take}
|
13
|
+
spec.description = <<-QUOTE.gsub(/^ /, '')
|
14
|
+
RSpecTimer will track the amount of time each of your tests take to complete,
|
15
|
+
and when it's done, can save the data to a YAML file.
|
16
|
+
QUOTE
|
17
|
+
spec.date = Time.now.utc.strftime("%Y-%m-%d")
|
18
|
+
spec.homepage = "http://github.com/tomchapin/rspec_timer"
|
19
|
+
spec.license = "MIT"
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0")
|
22
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.required_ruby_version = '>= 2.0'
|
27
|
+
spec.add_runtime_dependency 'method_source', '~> 0.8', '>= 0.8.2'
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec_timer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom Chapin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: method_source
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.8.2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.8'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.8.2
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.7'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.7'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
description: |
|
62
|
+
RSpecTimer will track the amount of time each of your tests take to complete,
|
63
|
+
and when it's done, can save the data to a YAML file.
|
64
|
+
email:
|
65
|
+
- tchapin@gmail.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- ".gitignore"
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- lib/rspec_timer.rb
|
76
|
+
- lib/rspec_timer/version.rb
|
77
|
+
- rspec_timer.gemspec
|
78
|
+
homepage: http://github.com/tomchapin/rspec_timer
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '2.0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.4.5
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Measure how long each of your RSpec tests take
|
102
|
+
test_files: []
|
103
|
+
has_rdoc:
|