rspec-blame 0.1.0
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.
- checksums.yaml +7 -0
- data/lib/rspec/blame.rb +42 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 79906c2df55b7377253151ed40488fbaf0e347cc
|
4
|
+
data.tar.gz: 4cfe0faafa74f482c0a25d0f2975b1bd033d9f81
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92ef755ac7d42a46a6d1567e5935e7effcb2f563e85e1abe3a234a5e61c2d2eaac54b00f2d204f8208a014233729f6dde39c4c09fdf002ce99d0a52838ca3720
|
7
|
+
data.tar.gz: 9125fccb6973e2a00e5cf589f564b80cf6f42811ac84ef75ef3f8263974928c1fe1ccf5a45ee07153d9ef416cbd98b702f0958d9fe68d51d26507cfcee264cdf
|
data/lib/rspec/blame.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rspec/core/formatters/progress_formatter'
|
2
|
+
|
3
|
+
# The formatter that parses each of the slowest example details and outputs git blame details.
|
4
|
+
class Blame < RSpec::Core::Formatters::ProgressFormatter
|
5
|
+
# Overrides ProgressFormatter's output.
|
6
|
+
# Usage: `rspec --profile --formatter Blame rspec_file.rb`
|
7
|
+
def dump_profile_slowest_examples
|
8
|
+
number_of_examples_to_profile = RSpec.configuration.profile_examples
|
9
|
+
|
10
|
+
slowest_examples = examples.sort_by(&_example_run_time).reverse.first(number_of_examples_to_profile)
|
11
|
+
|
12
|
+
_print_summary_for(slowest_examples)
|
13
|
+
slowest_examples.each do |example|
|
14
|
+
_print_details_for(example)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def _print_summary_for(slowest_examples)
|
19
|
+
slowest_tests_time, total_time = slowest_examples.map(&_example_run_time).inject { |sum, time| sum + time }, examples.map(&_example_run_time).inject { |sum, time| sum + time }
|
20
|
+
formatted_percentage = '%.1f' % (slowest_tests_time / total_time * 100)
|
21
|
+
|
22
|
+
output.puts "\nSlowest #{slowest_examples.size} examples finished in #{format_seconds(slowest_tests_time, 4)} secs (#{formatted_percentage}% of total time: #{format_seconds(total_time, 4)} secs).\n"
|
23
|
+
end
|
24
|
+
|
25
|
+
def _example_run_time
|
26
|
+
lambda { |example| example.execution_result[:run_time] }
|
27
|
+
end
|
28
|
+
|
29
|
+
def _print_details_for(example)
|
30
|
+
file, line_number = example.location.split(":")
|
31
|
+
git_blame_output = %x(git blame -c --date=short -L #{line_number},#{line_number} #{file})
|
32
|
+
blame = /(?<commit>\S+)\s*\((?<author>\D+)(?<date>\S+)/.match(git_blame_output)
|
33
|
+
commit_details = "Author: #{blame[:author].strip} (#{blame[:commit]}), Date: #{blame[:date]}"
|
34
|
+
|
35
|
+
output.puts " #{example.full_description}"
|
36
|
+
output.puts "%s %s %s" % [
|
37
|
+
color("#{format_seconds(_example_run_time.call(example), 4)} secs".rjust(15, ' '), :red),
|
38
|
+
color(example.location.ljust(80, ' '), :yellow),
|
39
|
+
color(commit_details.ljust(60, ' '), :cyan)
|
40
|
+
]
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-blame
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Seeto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |2
|
14
|
+
rspec-blame provides a Blame formatter that outputs the
|
15
|
+
author, commit, and date when profiling with RSpec.
|
16
|
+
email: seeto.david@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/rspec/blame.rb
|
22
|
+
homepage: http://rubygems.org/gems/rspec-blame
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.2.2
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Git blame the slowest RSpec examples.
|
46
|
+
test_files: []
|