rspec_overview 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f4558b861fa108b0a0810d3fae12a7a2ea625bf
4
+ data.tar.gz: 5bfea330b3482aa5b75337a4715950b1850e56f5
5
+ SHA512:
6
+ metadata.gz: b25e8431b9829f4958a17aed61ace2b4f1f782ca53eae84969c2be2f8ca5367f3ecd430c22d429d36605e28c03b1a9bdc2727acf28fd1c69b0fbee4aa7c495f3
7
+ data.tar.gz: b744a21eebfd6797b75a3ff0847bf17d1040dc78c5cd4155aea95cf0cbf5aaba3a1da249ba5c2362eecb93c67d4f60dda64ffe79a035a56d45229e41b8023233
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --require spec_helper
3
+ --format progress
4
+ --format RspecOverview::Formatter
@@ -0,0 +1 @@
1
+ 2.4.3
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3
5
+ - 2.4
6
+ - 2.5
7
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rspec_overview-formatter.gemspec
4
+ gemspec
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rspec_overview (0.1.0)
5
+ rspec-core (~> 3.0)
6
+ terminal-table (~> 1.6)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ byebug (9.1.0)
12
+ coderay (1.1.2)
13
+ diff-lcs (1.3)
14
+ method_source (0.9.0)
15
+ pry (0.11.3)
16
+ coderay (~> 1.1.0)
17
+ method_source (~> 0.9.0)
18
+ pry-byebug (3.5.1)
19
+ byebug (~> 9.1)
20
+ pry (~> 0.10)
21
+ rake (10.5.0)
22
+ rspec (3.7.0)
23
+ rspec-core (~> 3.7.0)
24
+ rspec-expectations (~> 3.7.0)
25
+ rspec-mocks (~> 3.7.0)
26
+ rspec-core (3.7.1)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-expectations (3.7.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-mocks (3.7.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.7.0)
34
+ rspec-support (3.7.0)
35
+ terminal-table (1.8.0)
36
+ unicode-display_width (~> 1.1, >= 1.1.1)
37
+ unicode-display_width (1.3.0)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bundler (~> 1.16)
44
+ pry-byebug (~> 3.5)
45
+ rake (~> 10.0)
46
+ rspec (~> 3.7)
47
+ rspec_overview!
48
+
49
+ BUNDLED WITH
50
+ 1.16.1
@@ -0,0 +1,86 @@
1
+ # RspecOverview
2
+
3
+ [![Build Status](https://travis-ci.org/odlp/rspec_overview.svg?branch=master)](https://travis-ci.org/odlp/rspec_overview)
4
+
5
+ Take `RspecOverview::Formatter` a spin when you're new to a project & need an
6
+ overview:
7
+
8
+ - How are the tests structured?
9
+ - How many tests are there by meta-type (feature, model, controller)?
10
+ - Which tests are taking the most time?
11
+
12
+ ## Usage
13
+
14
+ In your `Gemfile`:
15
+
16
+ ```ruby
17
+ group :test do
18
+ gem "rspec_overview"
19
+ end
20
+ ```
21
+
22
+ Then `bundle`. The overview formatter can be used standalone, or mix & match
23
+ with other formatters:
24
+
25
+ ```sh
26
+ # With the progress formatter:
27
+ bundle exec rspec --format progress --format RspecOverview::Formatter
28
+
29
+ # With the documentation formatter:
30
+ bundle exec rspec --format documentation --format RspecOverview::Formatter
31
+ ```
32
+
33
+ ## Example output
34
+
35
+ Run against [thoughtbot/administrate][administrate]:
36
+
37
+ [administrate]: https://github.com/thoughtbot/administrate
38
+
39
+ ```
40
+ Randomized with seed 40301
41
+ ................................................................................
42
+ ................................................................................
43
+ ................................................................................
44
+ ................................................................................
45
+ ...........................................
46
+
47
+ Finished in 19.36 seconds (files took 3.99 seconds to load)
48
+ 363 examples, 0 failures
49
+
50
+ Summary by Type or Subfolder
51
+ +---------------------+---------------+--------------+-------------------------+
52
+ | Type or Subfolder | Example count | Duration (s) | Average per example (s) |
53
+ +---------------------+---------------+--------------+-------------------------+
54
+ | feature | 83 | 9.88 | 0.11905 |
55
+ | controller | 46 | 3.56 | 0.07738 |
56
+ | generator | 73 | 2.49 | 0.03408 |
57
+ | ./spec/lib | 95 | 1.02 | 0.0107 |
58
+ | ./spec/i18n_spec.rb | 2 | 0.93344 | 0.46672 |
59
+ | view | 15 | 0.75198 | 0.05013 |
60
+ | model | 28 | 0.33824 | 0.01208 |
61
+ | ./spec/administrate | 5 | 0.06623 | 0.01325 |
62
+ | helper | 7 | 0.02385 | 0.00341 |
63
+ | ./spec/dashboards | 9 | 0.01684 | 0.00187 |
64
+ +---------------------+---------------+--------------+-------------------------+
65
+
66
+ Summary by File
67
+ +-------------------------------------------------------------+---------------+--------------+-------------------------+
68
+ | File | Example count | Duration (s) | Average per example (s) |
69
+ +-------------------------------------------------------------+---------------+--------------+-------------------------+
70
+ | ./spec/features/index_page_spec.rb | 11 | 2.09 | 0.1899 |
71
+ | ./spec/controllers/admin/blog/posts_controller_spec.rb | 16 | 1.64 | 0.1025 |
72
+ | ./spec/features/orders_form_spec.rb | 7 | 1.28 | 0.1825 |
73
+ | ./spec/i18n_spec.rb | 2 | 0.93344 | 0.46672 |
74
+ | ./spec/generators/routes_generator_spec.rb | 8 | 0.87447 | 0.10931 |
75
+ | ./spec/controllers/admin/log_entries_controller_spec.rb | 6 | 0.84819 | 0.14137 |
76
+ | ./spec/generators/dashboard_generator_spec.rb | 21 | 0.8094 | 0.03854 |
77
+ | ./spec/features/show_page_spec.rb | 9 | 0.79038 | 0.08782 |
78
+ | ./spec/lib/fields/date_time_spec.rb | 8 | 0.703 | 0.08787 |
79
+ | ./spec/features/orders_index_spec.rb | 6 | 0.67226 | 0.11204 |
80
+ | ./spec/features/log_entries_index_spec.rb | 6 | 0.66303 | 0.11051 |
81
+ | ./spec/features/search_spec.rb | 3 | 0.6555 | 0.2185 |
82
+ | <abridged> | <abridged> | <abridged> | <abridged> |
83
+ +-------------------------------------------------------------+---------------+--------------+-------------------------+
84
+
85
+ Randomized with seed 40301
86
+ ```
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rspec_overview/formatter"
5
+
6
+ require "pry"
7
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "rspec_overview/formatter"
2
+ require "rspec_overview/version"
3
+
4
+ module RspecOverview
5
+ end
@@ -0,0 +1,73 @@
1
+ require "rspec/core"
2
+ require "terminal-table"
3
+ require_relative "result_row"
4
+
5
+ module RspecOverview
6
+ class Formatter
7
+ RSpec::Core::Formatters.register self, :dump_summary
8
+
9
+ def initialize(output)
10
+ @output = output
11
+ end
12
+
13
+ def dump_summary(summary)
14
+ summarize_by_type(summary.examples)
15
+ summarize_by_file(summary.examples)
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :output
21
+
22
+ def summarize_by_type(examples)
23
+ summarize_by("Type or Subfolder", examples, &method(:type_or_subfolder))
24
+ end
25
+
26
+ def summarize_by_file(examples)
27
+ summarize_by("File", examples) { |example| example.file_path }
28
+ end
29
+
30
+ def summarize_by(column_name, examples)
31
+ data = {}
32
+
33
+ examples.each do |example|
34
+ identifier = yield(example) || "none"
35
+ data[identifier] ||= ResultRow.new(identifier)
36
+ data[identifier].example_count += 1
37
+ data[identifier].duration_raw += example.execution_result.run_time
38
+ end
39
+
40
+ headings = [
41
+ column_name, "Example count", "Duration (s)", "Average per example (s)"
42
+ ]
43
+
44
+ rows = values_in_descending_duration(data).map do |row|
45
+ [
46
+ row.identifier,
47
+ row.example_count,
48
+ helpers.format_seconds(row.duration_raw),
49
+ helpers.format_seconds(row.avg_duration),
50
+ ]
51
+ end
52
+
53
+ output.puts "\nSummary by #{column_name}"
54
+ print_table(headings: headings, rows: rows)
55
+ end
56
+
57
+ def type_or_subfolder(example)
58
+ example.metadata[:type] || example.file_path.slice(/.\/[^\/]+\/[^\/]+/)
59
+ end
60
+
61
+ def values_in_descending_duration(data)
62
+ data.values.sort_by(&:duration_raw).reverse_each
63
+ end
64
+
65
+ def helpers
66
+ RSpec::Core::Formatters::Helpers
67
+ end
68
+
69
+ def print_table(headings:, rows:)
70
+ output.puts Terminal::Table.new(headings: headings, rows: rows)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,14 @@
1
+ class ResultRow
2
+ attr_reader :identifier
3
+ attr_accessor :example_count, :duration_raw
4
+
5
+ def initialize(identifier)
6
+ @identifier = identifier
7
+ @example_count = 0
8
+ @duration_raw = 0.0
9
+ end
10
+
11
+ def avg_duration
12
+ duration_raw / example_count
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module RspecOverview
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "rspec_overview/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rspec_overview"
7
+ spec.version = RspecOverview::VERSION
8
+ spec.authors = ["Oli Peate"]
9
+ spec.email = ["oliverp@gmail.com"]
10
+
11
+ spec.summary = "See an overview of your RSpec test suite"
12
+ spec.homepage = "https://github.com/odlp/rspec_overview"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ f.match(%r{^(test|spec|features)/})
16
+ end
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rspec-core", "~> 3.0"
22
+ spec.add_dependency "terminal-table", "~> 1.6"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "pry-byebug", "~> 3.5"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.7"
28
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec_overview
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Oli Peate
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: terminal-table
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.7'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.7'
97
+ description:
98
+ email:
99
+ - oliverp@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".ruby-version"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/rspec_overview.rb
115
+ - lib/rspec_overview/formatter.rb
116
+ - lib/rspec_overview/result_row.rb
117
+ - lib/rspec_overview/version.rb
118
+ - rspec_overview.gemspec
119
+ homepage: https://github.com/odlp/rspec_overview
120
+ licenses: []
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.6.14
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: See an overview of your RSpec test suite
142
+ test_files: []