rspec-dump-profile-customizer 0.0.1
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.
- data/Gemfile +1 -0
- data/License.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +33 -0
- data/lib/rspec-dump-profile-customizer.rb +47 -0
- data/lib/rspec-dump-profile-customizer/version.rb +3 -0
- data/rspec-dump-profile-customizer.gemspec +28 -0
- metadata +83 -0
data/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gemspec
|
data/License.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2012 mori-dev
|
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 NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# RSpec Dump Profile Customizer
|
2
|
+
|
3
|
+
RSpecDumpProfileCustomizer provides report about worst N slow test and/or slow test over N seconds. You can set "N" in rails configuration file, application.rb. This is a small gem which modify dump_profile method in rspec for rails application. It therefore depends on rspec and rails.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem install rspec-dump-profile-customizer
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Set up rspec-dump-profile-customizer is easy. Just put it in your Gemfile and add your application.rb settings.
|
12
|
+
|
13
|
+
application.rb
|
14
|
+
|
15
|
+
config.rspec_dump_profile.number = 3
|
16
|
+
config.rspec_dump_profile.second = 0.5
|
17
|
+
|
18
|
+
Then, run your specs like this from now on:
|
19
|
+
|
20
|
+
$ bundle exec rspec -p spec/*/*_spec.rb
|
21
|
+
|
22
|
+
If you want to see slow tests as your default formatter, simply put the options in your .rspec file:
|
23
|
+
|
24
|
+
--profile
|
25
|
+
|
26
|
+
Then, run your specs like this from now on:
|
27
|
+
|
28
|
+
$ bundle exec rake spec
|
29
|
+
|
30
|
+
|
31
|
+
## Prerequisites
|
32
|
+
|
33
|
+
A Rails >= 3.0 Application with RSpec >= 2.0
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Fork, fix, then send me a pull request.
|
38
|
+
|
39
|
+
## Copyright
|
40
|
+
|
41
|
+
Copyright (c) mori-dev. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems' unless defined? Gem
|
2
|
+
require "rake"
|
3
|
+
require "rake/clean"
|
4
|
+
require "pathname"
|
5
|
+
|
6
|
+
task :default do
|
7
|
+
sh "rake -T"
|
8
|
+
end
|
9
|
+
|
10
|
+
CLEAN.include "rspec-dump-profile-customizer-*.gem"
|
11
|
+
|
12
|
+
|
13
|
+
namespace :gem do
|
14
|
+
|
15
|
+
desc "build rspec-dump-profile-customizer gem"
|
16
|
+
task :build do
|
17
|
+
sh "rake clean && gem build rspec-dump-profile-customizer.gemspec"
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "run gem install on the built gem"
|
21
|
+
task :install => :build do
|
22
|
+
sh "gem install rspec-dump-profile-customizer*.gem"
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "push rspec-dump-profile-customizer.gem to RubyGems"
|
26
|
+
task :release do
|
27
|
+
if Pathname.new("~/.gem/credentials").expand_path.exist?
|
28
|
+
sh "gem push rspec-dump-profile-customizer*.gem"
|
29
|
+
else
|
30
|
+
raise "Your rubygems.org credentials aren't set. Run `gem push` to set them."
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module RSpecDumpProfileCustomizer
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rails/engine'
|
5
|
+
require 'rspec/core/formatters/base_formatter'
|
6
|
+
require 'rspec/core/formatters/documentation_formatter'
|
7
|
+
|
8
|
+
class Railtie < ::Rails::Railtie
|
9
|
+
|
10
|
+
config.rspec_dump_profile = ActiveSupport::OrderedOptions.new
|
11
|
+
|
12
|
+
config.after_initialize do
|
13
|
+
|
14
|
+
RSpec::Core::Formatters::BaseTextFormatter.class_exec(config.rspec_dump_profile.number, config.rspec_dump_profile.second) do |number, second|
|
15
|
+
|
16
|
+
define_method("dump_profile") do
|
17
|
+
|
18
|
+
if number
|
19
|
+
sorted_examples_for_number = examples.sort_by {|example| example.execution_result[:run_time] }.
|
20
|
+
reverse.first(number)
|
21
|
+
total, slows = [examples, sorted_examples_for_number].map {|exs|
|
22
|
+
exs.inject(0.0) {|i, e| i + e.execution_result[:run_time] }}
|
23
|
+
time_taken = slows / total
|
24
|
+
percentage = '%.1f' % ((time_taken.nan? ? 0.0 : time_taken) * 100)
|
25
|
+
output.puts cyan("\nTop #{sorted_examples_for_number.size} slowest examples (#{format_seconds(slows)} seconds, #{percentage}% of total time):\n")
|
26
|
+
sorted_examples_for_number.each do |example|
|
27
|
+
output.puts " #{example.full_description}"
|
28
|
+
output.puts " #{yellow(format_seconds(example.execution_result[:run_time]))} #{yellow("seconds")} #{format_caller(example.location)}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if second
|
33
|
+
output.puts cyan("\nSlow examples (over #{second} seconds):\n")
|
34
|
+
sorted_examples_for_number = examples.sort_by { |example| example.execution_result[:run_time] }.
|
35
|
+
reverse.select { |example| example.execution_result[:run_time] > second.to_f }
|
36
|
+
sorted_examples_for_number.each do |example|
|
37
|
+
output.puts " #{example.full_description}"
|
38
|
+
output.puts " #{yellow(format_seconds(example.execution_result[:run_time]))} #{yellow("seconds")} #{format_caller(example.location)}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
rescue LoadError
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "rspec-dump-profile-customizer"
|
3
|
+
require "rspec-dump-profile-customizer/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rspec-dump-profile-customizer"
|
7
|
+
s.version = RSpecDumpProfileCustomizer::VERSION
|
8
|
+
s.authors = ["mori-dev"]
|
9
|
+
s.email = ["mori.dev.asdf@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/mori-dev/rspec-dump-profile-customizer"
|
11
|
+
s.summary = %q{RSpecDumpProfileCustomizer - a small rspec extension for detecting slow test in rails application}
|
12
|
+
s.description = <<-EOS
|
13
|
+
RSpecDumpProfileCustomizer provide report about worst N slow test and/or slow test over M seconds.
|
14
|
+
You can set "N" and "M" in rails configuration file, application.rb.
|
15
|
+
EOS
|
16
|
+
s.files = [
|
17
|
+
"Gemfile",
|
18
|
+
"README.md",
|
19
|
+
"Rakefile",
|
20
|
+
"License.txt",
|
21
|
+
"rspec-dump-profile-customizer.gemspec",
|
22
|
+
"lib/rspec-dump-profile-customizer.rb",
|
23
|
+
"lib/rspec-dump-profile-customizer/version.rb",
|
24
|
+
]
|
25
|
+
s.require_paths = ["lib"]
|
26
|
+
s.add_dependency "railties", ">= 3.0.0"
|
27
|
+
s.add_dependency "rspec", ">= 2.0.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-dump-profile-customizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- mori-dev
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: &2203460780 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2203460780
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &2203460280 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.0.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2203460280
|
36
|
+
description: ! " RSpecDumpProfileCustomizer provide report about worst N slow test
|
37
|
+
and/or slow test over M seconds.\n You can set \"N\" and \"M\" in rails configuration
|
38
|
+
file, application.rb.\n"
|
39
|
+
email:
|
40
|
+
- mori.dev.asdf@gmail.com
|
41
|
+
executables: []
|
42
|
+
extensions: []
|
43
|
+
extra_rdoc_files: []
|
44
|
+
files:
|
45
|
+
- Gemfile
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- License.txt
|
49
|
+
- rspec-dump-profile-customizer.gemspec
|
50
|
+
- lib/rspec-dump-profile-customizer.rb
|
51
|
+
- lib/rspec-dump-profile-customizer/version.rb
|
52
|
+
homepage: https://github.com/mori-dev/rspec-dump-profile-customizer
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
hash: -249835232104295534
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
hash: -249835232104295534
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.8.11
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: RSpecDumpProfileCustomizer - a small rspec extension for detecting slow test
|
82
|
+
in rails application
|
83
|
+
test_files: []
|