rspec-blame 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f2581ea0444b1dbf50a23c0afe9e37342b4b4ea
4
- data.tar.gz: a17c38ba2013978c08549b6733cf6400b3c9664f
3
+ metadata.gz: 2b131572f2575e37af96e3ba1657f1cfbc78bc15
4
+ data.tar.gz: 2f16ccd3a4fc75fe14fe0ebff5e05d1b52dcfbf9
5
5
  SHA512:
6
- metadata.gz: fab4bc385d851a834e6354b8f8525871c3424538aa9dad1c48c351f4320dd4060d8a0d86de8c95015838aea024818cf63094a308aa534fb5b960d391a9e433f7
7
- data.tar.gz: 4abad81e752070ddf79b9361a884bd88ea1a86ac43b7b1c6606c36f1970c69641bff35fa3f07ca85fb1de87743cf7cca5b83b0d7c761a7ac3682363a07338b14
6
+ metadata.gz: 2dc22e8a4ef94d62291e9f4eb27359d1cdbdbe39ee6db6df78d7471aac1ccae15b83b52431c8b7f9ec7d5a14c086c6eb50ff76127ba477ed86c03bad4388ad6d
7
+ data.tar.gz: 7447dcebd308f8b797fcfb313f9dc7cbf1c0051db2c30486ebad56c15e5b1373992074be8a595433a607ab71fa14ac8c2d5ceacd6757336d5557d455a212d917
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --profile
2
+ --color
3
+ --format RSpec::Blame
4
+ --require spec_helper
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  gem "rspec-core", ["~> 2.14"]
4
4
 
5
- group :develpoment do
5
+ group :test do
6
6
  gem "rake"
7
7
  gem "mocha"
8
8
  gem "rspec"
data/README.md CHANGED
@@ -1,66 +1,128 @@
1
1
  # rspec-blame
2
2
 
3
- rspec-blame provides a Blame RSpec foramtter that outputs the author, commit hash, and
4
- commit date for the slowest examples when profiling with RSpec in a **git** project.
3
+ rspec-blame provides a Blame RSpec formatter that outputs the author, commit hash, and
4
+ commit date for the slowest examples when profiling with RSpec in a **git** project. It
5
+ also allows a profile threshold to be set, only printing examples that exceed the threshold.
5
6
 
6
- ## Usage
7
+ ### Goals
7
8
 
8
- gem 'rspec-blame'
9
+ In an application that has good test coverage and is managed by multiple people, tests are
10
+ constantly added and executed. Often, code that result in slow tests can make the development
11
+ process slow as well. To avoid this problem, this gem attempts to faciliate good practices
12
+ through accomplishing the following goals:
9
13
 
10
- After including the above line in your Gemfile and running `bundle install`, there are
11
- several ways to use the formatter:
14
+ * Output the commit information of the slow tests, allowing the developer who last touched it
15
+ and who also has the most recent context to go back and optimize the code.
16
+ * Provide the ability to set a threshold of what are considered slow tests, reducing the noise
17
+ when profiling.
12
18
 
13
- ### Command Line
19
+ Happy testing!
14
20
 
15
- `rspec --require rspec/blame --profile --format Blame file_spec.rb` or `rspec -r rspec/blame -p -f Blame file_spec.rb`
21
+ ### Example Output
16
22
 
17
- ### Rake Task
23
+ ```
24
+ ................
25
+
26
+ Printing examples and example groups exceeding the profile threshold (0.000001 secs):
27
+
28
+ Slowest 10 examples finished in 0.0168 secs (77.0% of total time: 0.0219 secs).
29
+ Blame dump_profile_slowest_examples prints the number of examples to profile
30
+ 0.0022 secs ./spec/lib/rspec/blame_spec.rb:28 Author: Braintree, Date: 2014-05-28, Hash: c8c20b05
31
+ Blame dump_profile_slowest_example_groups prints the average time taken for the slowest example groups
32
+ 0.0021 secs ./spec/lib/rspec/blame_spec.rb:134 Author: dseeto, Date: 2014-07-25, Hash: 7612bbba
33
+ Blame dump_profile_slowest_examples does not print examples if execution time is under profile_threshold
34
+ 0.0019 secs ./spec/lib/rspec/blame_spec.rb:80 Author: dseeto, Date: 2014-07-11, Hash: 8afdd0fc
35
+ Blame dump_profile_slowest_examples prints summary including author, commit, and date
36
+ 0.0017 secs ./spec/lib/rspec/blame_spec.rb:73 Author: Braintree, Date: 2014-05-28, Hash: c8c20b05
37
+ Blame dump_profile_slowest_examples prints the example_group size if less than the number of examples to profile
38
+ 0.0017 secs ./spec/lib/rspec/blame_spec.rb:35 Author: dseeto, Date: 2014-07-11, Hash: 8afdd0fc
39
+ Blame dump_profile_slowest_example_groups prints the name of the slowest example groups
40
+ 0.0016 secs ./spec/lib/rspec/blame_spec.rb:141 Author: dseeto, Date: 2014-07-25, Hash: 7612bbba
41
+ Blame dump_profile_slowest_example_groups prints the path to test example group
42
+ 0.0015 secs ./spec/lib/rspec/blame_spec.rb:149 Author: dseeto, Date: 2014-07-25, Hash: 7612bbba
43
+ Blame dump_profile_slowest_example_groups prints the number of example_groups to profile
44
+ 0.0014 secs ./spec/lib/rspec/blame_spec.rb:119 Author: dseeto, Date: 2014-07-25, Hash: 7612bbba
45
+ Blame dump_profile_slowest_example_groups prints the number of example_groups if less than the number of examples to profile
46
+ 0.0014 secs ./spec/lib/rspec/blame_spec.rb:126 Author: dseeto, Date: 2014-07-25, Hash: 7612bbba
47
+ Blame dump_profile_slowest_example_groups does not print examples if execution time is under profile_threshold
48
+ 0.0014 secs ./spec/lib/rspec/blame_spec.rb:157 Author: dseeto, Date: 2014-07-25, Hash: 7612bbba
49
+
50
+ Slowest 2 example groups:
51
+ Blame
52
+ 0.0016 secs avg ./spec/lib/rspec/blame_spec.rb Execution Time: 0.0217 secs, Examples: 14
53
+ RSpec::Core::Configuration
54
+ 0.0001 secs avg ./spec/lib/rspec/blame/configuration_spec.rb Execution Time: 0.0002 secs, Examples: 2
55
+
56
+ Profiling finished in 0.0860 secs.
57
+
58
+ Finished in 0.02312 seconds
59
+ 16 examples, 0 failures
60
+ ```
18
61
 
19
- ```ruby
20
- require "rspec/blame"
21
- require "rspec/core/rake_task"
62
+ ### Usage
22
63
 
23
- RSpec::Core::RakeTask.new(:spec) { |t| t.rspec_opts = "-p -f Blame" }
64
+ ```
65
+ gem "rspec-blame"
24
66
  ```
25
67
 
26
- ### Configure RSpec
68
+ After including the above line in your Gemfile and running `bundle install`, you may set a profile
69
+ threshold by adding the following to `spec/spec_herlper.rb`:
27
70
 
28
- Add `--require "rspec/blame"`, `--profile`, and `--format Blame` to your `.rspec` file.
71
+ ```
72
+ RSpec.configure do |config|
73
+ config.profile_threshold = 1
74
+ end
75
+ ```
29
76
 
30
- Alternatively, add `require "spec_helper"` to any spec files and add the following to
31
- your spec_helper.rb:
77
+ and adding the following to your `.rspec` file:
32
78
 
33
- ```ruby
34
- Rspec.configure do |config|
35
- config.profile_examples = true
36
- config.format = Blame
37
- end
79
+ ```
80
+ --require "spec_helper"
81
+ ```
82
+
83
+ There are several ways to use the formatter:
84
+
85
+ #### Command Line With Specific Spec Files
86
+
87
+ ```
88
+ rspec -p -f Blame file_spec.rb
38
89
  ```
39
90
 
40
- ## Output
91
+ or
41
92
 
42
93
  ```
43
- ......
94
+ rspec --profile --format Blame file_spec.rb
95
+ ```
96
+
97
+ #### Rake Task
98
+
99
+ ```
100
+ require "rspec/core/rake_task"
101
+
102
+ RSpec::Core::RakeTask.new(:spec) { |t| t.rspec_opts = "-p -f Blame" }
103
+ ```
104
+
105
+ #### Any Usage of RSpec
44
106
 
45
- Slowest 6 examples finished in 0.0074 secs (100.0% of total time: 0.0074 secs).
46
- Blame dump_profile_slowest_examples prints the number of examples to profile
47
- 0.0016 secs ./spec/lib/rspec/blame_spec.rb:21 Author: dseeto (i0r2i2s5), Date: 2014-05-28
48
- Blame dump_profile_slowest_examples prints summary including author, commit, and date
49
- 0.0012 secs ./spec/lib/rspec/blame_spec.rb:42 Author: dseeto (i0r2i2s5), Date: 2014-05-28
50
- Blame dump_profile_slowest_examples prints the time taken for the slowest tests
51
- 0.0012 secs ./spec/lib/rspec/blame_spec.rb:25 Author: dseeto (i0r2i2s5), Date: 2014-05-28
52
- Blame dump_profile_slowest_examples prints the path to test example
53
- 0.0012 secs ./spec/lib/rspec/blame_spec.rb:37 Author: dseeto (i0r2i2s5), Date: 2014-05-28
54
- Blame dump_profile_slowest_examples prints the percentage taken from the total time
55
- 0.0011 secs ./spec/lib/rspec/blame_spec.rb:33 Author: dseeto (i0r2i2s5), Date: 2014-05-28
56
- Blame dump_profile_slowest_examples prints the name of the examples
57
- 0.0011 secs ./spec/lib/rspec/blame_spec.rb:29 Author: dseeto (i0r2i2s5), Date: 2014-05-28
107
+ Add the following to your `.rspec` file:
58
108
 
59
- Finished in 0.00792 seconds
60
- 6 examples, 0 failures
109
+ ```
110
+ --profile
111
+ --format Blame
112
+ ```
113
+
114
+ #### With Spec Helper
115
+ Add `require "spec_helper"` to any spec files and add the following to
116
+ your spec_helper.rb:
117
+
118
+ ```
119
+ Rspec.configure do |config|
120
+ config.profile_examples = true
121
+ config.formatter = Blame
122
+ end
61
123
  ```
62
124
 
63
- ## Author
125
+ ### Author
64
126
 
65
127
  [David Seeto](https://github.com/dseeto)
66
128
 
@@ -0,0 +1,5 @@
1
+ require "rspec/core"
2
+
3
+ class RSpec::Core::Configuration
4
+ self.add_setting :profile_threshold
5
+ end
data/lib/rspec/blame.rb CHANGED
@@ -1,36 +1,53 @@
1
1
  require "rspec/core/formatters/progress_formatter"
2
+ require "rspec/blame/configuration"
2
3
 
3
4
  # Formatter that ouputs git blame details for the slowest examples.
4
5
  class Blame < RSpec::Core::Formatters::ProgressFormatter
6
+ # Prints out profile results and profile threshold if set in RSpec.configuration.
7
+ def dump_profile
8
+ start = Time.now
9
+ _print_profile_threshold unless _profile_threshold.nil?
10
+ dump_profile_slowest_examples
11
+ dump_profile_slowest_example_groups
12
+ output.puts "\nProfiling finished in #{_format_seconds(Time.now - start)} secs."
13
+ end
14
+
15
+ def _print_profile_threshold
16
+ output.puts "\nPrinting examples and example groups exceeding the profile threshold (#{_format_seconds(_profile_threshold)} secs):"
17
+ end
18
+
5
19
  # Appends to ProgressFormatter's output by executing git blame in a subprocess and parsing its output.
6
20
  def dump_profile_slowest_examples
7
- number_of_examples_to_profile = RSpec.configuration.profile_examples
21
+ slowest_examples = _slowest_examples(examples)
8
22
 
9
- slowest_examples = examples.sort_by(&_example_run_time).reverse.first(number_of_examples_to_profile)
23
+ return output.puts color("\nAll examples are faster than #{_format_seconds(_profile_threshold)} secs.", :green) if _profile_threshold && slowest_examples.empty?
10
24
 
11
- _print_summary_for(slowest_examples)
25
+ _print_example_summary(slowest_examples)
12
26
  slowest_examples.each do |example|
13
- _print_details_for(example)
27
+ _print_example_details(example)
14
28
  end
15
29
  end
16
30
 
17
- def _print_summary_for(slowest_examples)
18
- 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 }
31
+ def _slowest_examples(examples)
32
+ slowest_examples = examples.sort_by(&_example_run_time).reverse.first(_number_of_examples_to_profile)
33
+ _profile_threshold ? slowest_examples.select { |example| _example_run_time.call(example) > _profile_threshold } : slowest_examples
34
+ end
35
+
36
+ def _print_example_summary(slowest_examples)
37
+ slowest_tests_time = _total_time(slowest_examples)
38
+ total_time = _total_time(examples)
19
39
  formatted_percentage = '%.1f' % (slowest_tests_time / total_time * 100)
20
40
 
21
- 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"
22
- end
41
+ number_of_test = "\nSlowest #{pluralize(slowest_examples.size, "example")} "
42
+ slowest_total_time = "finished in #{_format_seconds(slowest_tests_time)} secs "
43
+ percent_and_total = "(#{formatted_percentage}% of total time: #{_format_seconds(total_time)} secs).\n"
23
44
 
24
- def _example_run_time
25
- lambda { |example| example.execution_result[:run_time] }
45
+ output.puts number_of_test + slowest_total_time + percent_and_total
26
46
  end
27
47
 
28
- def _print_details_for(example)
48
+ def _print_example_details(example)
29
49
  output.puts " #{example.full_description}"
30
- output.print "%s %s" % [
31
- color("#{format_seconds(_example_run_time.call(example), 4)} secs".rjust(15, ' '), :red),
32
- color(example.location.ljust(80, ' '), :yellow)
33
- ]
50
+ output.print "#{color(" #{_format_seconds(_example_run_time.call(example))} secs".ljust(19, ' '), :red)}" + " #{color(example.location.ljust(79, ' '), :yellow)}"
34
51
 
35
52
  file, line_number = example.location.split(":")
36
53
  git_blame_output = %x(git blame -c --date=short -L #{line_number},#{line_number} #{file})
@@ -39,8 +56,70 @@ class Blame < RSpec::Core::Formatters::ProgressFormatter
39
56
  if blame.nil?
40
57
  output.puts
41
58
  else
42
- commit_details = "Author: #{blame[:author].strip} (#{blame[:commit]}), Date: #{blame[:date]}"
59
+ commit_details = " Author: #{blame[:author].strip}, Date: #{blame[:date]}, Hash: #{blame[:commit]}"
43
60
  output.puts(color(commit_details.ljust(60, ' '), :cyan))
44
61
  end
45
62
  end
63
+
64
+ def _total_time(examples)
65
+ examples.map(&_example_run_time).inject { |sum, time| sum + time }
66
+ end
67
+
68
+ # Prints example group profiling result.
69
+ def dump_profile_slowest_example_groups
70
+ slowest_example_groups = _slowest_example_groups(examples)
71
+
72
+ return output.puts color("\nAll example groups are faster than #{_format_seconds(_profile_threshold)} secs.", :green) if _profile_threshold && slowest_example_groups.empty?
73
+
74
+ _print_example_group_summary(slowest_example_groups)
75
+ slowest_example_groups.each do |location, details|
76
+ _print_example_group_details(location, details)
77
+ end
78
+ end
79
+
80
+ def _slowest_example_groups(examples)
81
+ slowest_example_groups = {}
82
+ examples.each do |example|
83
+ location = example.example_group.parent_groups.last.metadata[:example_group][:location]
84
+ slowest_example_groups[location] ||= Hash.new(0)
85
+ slowest_example_groups[location][:total_time] += example.execution_result[:run_time]
86
+ slowest_example_groups[location][:count] += 1
87
+ slowest_example_groups[location][:description] = example.example_group.top_level_description unless slowest_example_groups[location].has_key?(:description)
88
+ end
89
+ slowest_example_groups.each { |location, details| details[:average] = details[:total_time].to_f / details[:count] }
90
+
91
+ sorted_example_groups = slowest_example_groups.sort_by { |location, details| details[:average] }.reverse.first(_number_of_examples_to_profile)
92
+
93
+ _profile_threshold ? sorted_example_groups.select { |location, details| details[:average] > _profile_threshold } : sorted_example_groups
94
+ end
95
+
96
+ def _print_example_group_summary(slowest_example_groups)
97
+ output.puts "\nSlowest #{pluralize(slowest_example_groups.size, "example group")}:"
98
+ end
99
+
100
+ def _print_example_group_details(location, details)
101
+ output.puts " #{details[:description]}"
102
+
103
+ average = color("#{_format_seconds(details[:average])} secs avg".ljust(15, " "), :red)
104
+ total = "#{_format_seconds(details[:total_time])} secs"
105
+ count = "#{details[:count]}"
106
+ calc = color(" Execution Time: #{total}, Examples: #{count}".ljust(60, " "), :cyan)
107
+ output.puts " #{average}" + " #{color(location.split(":")[0].ljust(79, ' '), :yellow)}" + calc
108
+ end
109
+
110
+ def _example_run_time
111
+ lambda { |example| example.execution_result[:run_time] }
112
+ end
113
+
114
+ def _number_of_examples_to_profile
115
+ RSpec.configuration.profile_examples
116
+ end
117
+
118
+ def _profile_threshold
119
+ RSpec.configuration.profile_threshold
120
+ end
121
+
122
+ def _format_seconds(float)
123
+ formatted = "%.#{float >= 1 ? 2 : 4}f" % float
124
+ end
46
125
  end
data/rspec-blame.gemspec CHANGED
@@ -1,7 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "rspec-blame"
3
- s.version = "0.1.2"
4
- s.date = "2014-05-23"
3
+ s.version = "0.2.0"
5
4
  s.license = "MIT"
6
5
 
7
6
  s.authors = ["David Seeto"]
@@ -9,7 +8,7 @@ Gem::Specification.new do |s|
9
8
  s.homepage = "https://github.com/dseeto/rspec-blame"
10
9
 
11
10
  s.summary = "Git blame when profiling your slowest RSpec examples."
12
- s.description = %q{rspec-blame provides a Blame formatter that outputs git blame details for the slowest examples when profiling with RSpec.}
11
+ s.description = %q{rspec-blame provides a Blame formatter that outputs git blame details for the slowest examples above a profile threshold when profiling with RSpec.}
13
12
  s.files = `git ls-files`.split("\n")
14
13
 
15
14
  s.add_runtime_dependency "rspec-core", ["~> 2.14"]
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe RSpec::Core::Configuration do
4
+ it "adds profile_threshold as a customer setting" do
5
+ RSpec.configuration.respond_to?(:profile_threshold).should == true
6
+ end
7
+
8
+ it "sets the profile_threshold customer setting" do
9
+ RSpec.configuration.profile_threshold = 3
10
+ RSpec.configuration.profile_threshold.should == 3
11
+ end
12
+ end
@@ -1,46 +1,165 @@
1
1
  require "spec_helper"
2
- require "rspec"
3
- require "rspec/blame"
4
2
 
5
3
  describe Blame do
6
- let(:output) { StringIO.new }
7
-
8
4
  describe "dump_profile_slowest_examples" do
9
- before do
10
- RSpec.configuration.stubs(:profile_examples).returns(1)
11
- group = RSpec::Core::ExampleGroup.describe("group") { example("example") { sleep 0.001 } }
12
- group.examples.each { |example| example.execution_result[:run_time] = 0.42 }
5
+ before(:each) {
6
+ @output = StringIO.new
13
7
 
14
- formatter = Blame.new(output)
15
- formatter.stubs(:examples).returns(group.examples)
16
- formatter.expects(:`).returns("i0r2i2s5 ( dseeto 2014-05-23 10)")
8
+ @group = RSpec::Core::ExampleGroup.describe("group")
9
+ @fast_example = RSpec::Core::Example.new(@group, "fast example", @group.metadata).tap do |example|
10
+ example.execution_result[:run_time] = 0.1
11
+ end
12
+ @slower_example = RSpec::Core::Example.new(@group, "slower example", @group.metadata).tap do |example|
13
+ example.execution_result[:run_time] = 1
14
+ end
15
+ @slow_example = RSpec::Core::Example.new(@group, "slow example", @group.metadata).tap do |example|
16
+ example.execution_result[:run_time] = 10
17
+ end
18
+ @group.examples << @fast_example << @slower_example << @slow_example
17
19
 
18
- formatter.dump_profile_slowest_examples
19
- end
20
+ @formatter = Blame.new(@output).tap do |f|
21
+ f.stubs(:examples).returns(@group.examples)
22
+ f.stubs(:`).returns("i0r2i2s5 ( dseeto 2014-05-23 10)")
23
+
24
+ RSpec.configuration.profile_threshold = nil
25
+ end
26
+ }
20
27
 
21
28
  it "prints the number of examples to profile" do
22
- expect(output.string).to match(/Slowest 1 examples/)
29
+ RSpec.configuration.stubs(:profile_examples).returns(2)
30
+ @formatter.dump_profile_slowest_examples
31
+
32
+ expect(@output.string).to include("Slowest 2 examples")
33
+ end
34
+
35
+ it "prints the example_group size if less than the number of examples to profile" do
36
+ RSpec.configuration.stubs(:profile_examples).returns(10)
37
+ @formatter.dump_profile_slowest_examples
38
+
39
+ expected_output = "Slowest #{@group.examples.size} examples"
40
+ expect(@output.string).to include(expected_output)
23
41
  end
24
42
 
25
43
  it "prints the time taken for the slowest tests" do
26
- expect(output.string).to match(/finished in 0\.42 secs/)
44
+ RSpec.configuration.stubs(:profile_examples).returns(1)
45
+ @formatter.dump_profile_slowest_examples
46
+
47
+ expect(@output.string).to include("finished in #{@slow_example.execution_result[:run_time]}")
27
48
  end
28
49
 
29
50
  it "prints the name of the examples" do
30
- expect(output.string).to match(/group example/m)
51
+ RSpec.configuration.stubs(:profile_examples).returns(2)
52
+ @formatter.dump_profile_slowest_examples
53
+
54
+ expect(@output.string).to include("group #{@slow_example.description}")
55
+ expect(@output.string).to include("group #{@slower_example.description}")
31
56
  end
32
57
 
33
58
  it "prints the percentage taken from the total time" do
34
- expect(output.string).to match(/100.0% of total time/)
59
+ RSpec.configuration.stubs(:profile_examples).returns(3)
60
+ @formatter.dump_profile_slowest_examples
61
+
62
+ expect(@output.string).to include("100.0% of total time")
35
63
  end
36
64
 
37
65
  it "prints the path to test example" do
66
+ RSpec.configuration.stubs(:profile_examples).returns(1)
67
+ @formatter.dump_profile_slowest_examples
68
+
38
69
  filename = __FILE__.split(File::SEPARATOR).last
39
- expect(output.string).to match(/#{filename}\:11/)
70
+ expect(@output.string).to include("#{filename}\:15")
40
71
  end
41
72
 
42
73
  it "prints summary including author, commit, and date" do
43
- expect(output.string).to match(/Author:.*\(.*\), Date:/)
74
+ RSpec.configuration.stubs(:profile_examples).returns(1)
75
+ @formatter.dump_profile_slowest_examples
76
+
77
+ expect(@output.string).to match(/Author: .*, Date: .*, Hash:/)
78
+ end
79
+
80
+ it "does not print examples if execution time is under profile_threshold" do
81
+ RSpec.configuration.stubs(:profile_examples).returns(10)
82
+ RSpec.configuration.profile_threshold = 5.00
83
+ @formatter.dump_profile_slowest_examples
84
+
85
+ expect(@output.string).to include("Slowest 1 example finished in #{@slow_example.execution_result[:run_time]}")
86
+ end
87
+ end
88
+
89
+ describe "dump_profile_slowest_example_groups" do
90
+ before(:each) {
91
+ @output = StringIO.new
92
+
93
+ @fast_group = RSpec::Core::ExampleGroup.describe("fast group")
94
+ @fast_example = RSpec::Core::Example.new(@fast_group, "fast example", @fast_group.metadata).tap do |example|
95
+ example.execution_result[:run_time] = 0.1
96
+ end
97
+ @fast_group.examples << @fast_example
98
+
99
+ @slower_group = RSpec::Core::ExampleGroup.describe("slower group")
100
+ @slower_example = RSpec::Core::Example.new(@slower_group, "slower example", @slower_group.metadata).tap do |example|
101
+ example.execution_result[:run_time] = 1
102
+ end
103
+ @slower_group.examples << @slower_example
104
+
105
+ @slow_group = RSpec::Core::ExampleGroup.describe("slow group")
106
+ @slow_example = RSpec::Core::Example.new(@slow_group, "slow example", @slow_group.metadata).tap do |example|
107
+ example.execution_result[:run_time] = 10
108
+ end
109
+ @slow_group.examples << @slow_example
110
+
111
+ @formatter = Blame.new(@output).tap do |f|
112
+ f.stubs(:examples).returns(@slow_group.examples.zip(@slower_group.examples, @fast_group.examples).flatten)
113
+ f.stubs(:`).returns("i0r2i2s5 ( dseeto 2014-05-23 10)")
114
+
115
+ RSpec.configuration.profile_threshold = nil
116
+ end
117
+ }
118
+
119
+ it "prints the number of example_groups to profile" do
120
+ RSpec.configuration.stubs(:profile_examples).returns(2)
121
+ @formatter.dump_profile_slowest_example_groups
122
+
123
+ expect(@output.string).to include("Slowest 2 example groups")
124
+ end
125
+
126
+ it "prints the number of example_groups if less than the number of examples to profile" do
127
+ RSpec.configuration.stubs(:profile_examples).returns(10)
128
+ @formatter.dump_profile_slowest_example_groups
129
+
130
+ expected_output = "Slowest #{@formatter.examples.size} example groups"
131
+ expect(@output.string).to include(expected_output)
132
+ end
133
+
134
+ it "prints the average time taken for the slowest example groups" do
135
+ RSpec.configuration.stubs(:profile_examples).returns(1)
136
+ @formatter.dump_profile_slowest_example_groups
137
+
138
+ expect(@output.string).to include("10.00 secs avg")
139
+ end
140
+
141
+ it "prints the name of the slowest example groups" do
142
+ RSpec.configuration.stubs(:profile_examples).returns(2)
143
+ @formatter.dump_profile_slowest_example_groups
144
+
145
+ expect(@output.string).to include("#{@slow_group.description}")
146
+ expect(@output.string).to include("#{@slower_group.description}")
147
+ end
148
+
149
+ it "prints the path to test example group" do
150
+ RSpec.configuration.stubs(:profile_examples).returns(1)
151
+ @formatter.dump_profile_slowest_example_groups
152
+
153
+ filename = __FILE__.split(File::SEPARATOR).last
154
+ expect(@output.string).to include("#{filename}")
155
+ end
156
+
157
+ it "does not print examples if execution time is under profile_threshold" do
158
+ RSpec.configuration.stubs(:profile_examples).returns(10)
159
+ RSpec.configuration.profile_threshold = 15.00
160
+ @formatter.dump_profile_slowest_example_groups
161
+
162
+ expect(@output.string).to include ("All example groups are faster than #{@formatter._format_seconds(RSpec.configuration.profile_threshold)} secs.")
44
163
  end
45
164
  end
46
165
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,11 @@
1
+ require "rspec"
2
+ require "mocha"
3
+ require "rspec/blame"
4
+ require "rspec/blame/configuration"
5
+
1
6
  ENV["RAILS_ENV"] ||= "test"
2
7
 
3
8
  RSpec.configure do |config|
4
9
  config.mock_with :mocha
10
+ config.profile_threshold = 0
5
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-blame
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Seeto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-23 00:00:00.000000000 Z
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core
@@ -67,18 +67,21 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: rspec-blame provides a Blame formatter that outputs git blame details
70
- for the slowest examples when profiling with RSpec.
70
+ for the slowest examples above a profile threshold when profiling with RSpec.
71
71
  email: seeto.david@gmail.com
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - .gitignore
77
+ - .rspec
77
78
  - Gemfile
78
79
  - README.md
79
80
  - Rakefile
80
81
  - lib/rspec/blame.rb
82
+ - lib/rspec/blame/configuration.rb
81
83
  - rspec-blame.gemspec
84
+ - spec/lib/rspec/blame/configuration_spec.rb
82
85
  - spec/lib/rspec/blame_spec.rb
83
86
  - spec/spec_helper.rb
84
87
  homepage: https://github.com/dseeto/rspec-blame
@@ -101,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
104
  version: '0'
102
105
  requirements: []
103
106
  rubyforge_project:
104
- rubygems_version: 2.2.2
107
+ rubygems_version: 2.0.14
105
108
  signing_key:
106
109
  specification_version: 4
107
110
  summary: Git blame when profiling your slowest RSpec examples.