rspec_overview 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/README.md +11 -3
- data/Rakefile +6 -1
- data/lib/rspec_overview.rb +1 -0
- data/lib/rspec_overview/formatter.rb +24 -33
- data/lib/rspec_overview/formatter_csv.rb +13 -0
- data/lib/rspec_overview/output/csv.rb +22 -0
- data/lib/rspec_overview/output/table.rb +16 -0
- data/lib/rspec_overview/result.rb +28 -0
- data/lib/rspec_overview/version.rb +1 -1
- metadata +7 -3
- data/lib/rspec_overview/result_row.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91ecf4bf56b43ba4727d25899adcc5523827de5c
|
4
|
+
data.tar.gz: 3b280c205f00035b4455644041daf5bbdb73fd55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48e0d3b44f2cd9e4d71c8978df408e884560123c1c51bf053f316f2f8a3385de27a6f6eebdcc836b1bda9571a3bb041b6c1ae9e9f5d3989bccae9a2a22f87119
|
7
|
+
data.tar.gz: c524cde83bcf2ba4c857787132c1d7d685b10a32d1f6afb0cb336f2c6add205bb8fb7b96c894a0f2abac580b3011172bb29093ddd767fced9e1832a2b2c465a2
|
data/.rspec
CHANGED
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/odlp/rspec_overview.svg?branch=master)](https://travis-ci.org/odlp/rspec_overview)
|
4
4
|
|
5
|
-
Take `RspecOverview::Formatter` a spin when you're new to a project and need
|
6
|
-
overview:
|
5
|
+
Take `RspecOverview::Formatter` for a spin when you're new to a project and need
|
6
|
+
an overview:
|
7
7
|
|
8
8
|
- How are the tests structured?
|
9
|
-
- How many tests are there by
|
9
|
+
- How many tests are there by type (feature, model, controller)?
|
10
10
|
- Which tests are taking the most time?
|
11
11
|
|
12
12
|
## Usage
|
@@ -30,6 +30,14 @@ bundle exec rspec --format progress --format RspecOverview::Formatter
|
|
30
30
|
bundle exec rspec --format documentation --format RspecOverview::Formatter
|
31
31
|
```
|
32
32
|
|
33
|
+
### CSV format
|
34
|
+
|
35
|
+
You can also produce a CSV for further analysis:
|
36
|
+
|
37
|
+
```sh
|
38
|
+
bundle exec rspec --format RspecOverview::FormatterCsv --out overview.csv
|
39
|
+
```
|
40
|
+
|
33
41
|
## Example output
|
34
42
|
|
35
43
|
Run against [thoughtbot/administrate][administrate]:
|
data/Rakefile
CHANGED
@@ -3,4 +3,9 @@ require "rspec/core/rake_task"
|
|
3
3
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
|
-
|
6
|
+
RSpec::Core::RakeTask.new(:spec_with_formatters) do |t|
|
7
|
+
t.rspec_opts =
|
8
|
+
"--format RspecOverview::Formatter --format RspecOverview::FormatterCsv"
|
9
|
+
end
|
10
|
+
|
11
|
+
task default: [:spec, :spec_with_formatters]
|
data/lib/rspec_overview.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "rspec/core"
|
2
|
-
|
3
|
-
require_relative "
|
2
|
+
require_relative "output/table"
|
3
|
+
require_relative "result"
|
4
4
|
|
5
5
|
module RspecOverview
|
6
6
|
class Formatter
|
@@ -20,7 +20,9 @@ module RspecOverview
|
|
20
20
|
attr_reader :output
|
21
21
|
|
22
22
|
def summarize_by_type(examples)
|
23
|
-
summarize_by("Type or Subfolder", examples
|
23
|
+
summarize_by("Type or Subfolder", examples) do |example|
|
24
|
+
example.metadata[:type] || extract_subfolder(example.file_path)
|
25
|
+
end
|
24
26
|
end
|
25
27
|
|
26
28
|
def summarize_by_file(examples)
|
@@ -28,51 +30,40 @@ module RspecOverview
|
|
28
30
|
end
|
29
31
|
|
30
32
|
def summarize_by(column_name, examples)
|
31
|
-
|
33
|
+
results = {}
|
32
34
|
|
33
35
|
examples.each do |example|
|
34
36
|
identifier = yield(example) || "none"
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
results[identifier] ||= Result.new(identifier)
|
38
|
+
results[identifier].example_count += 1
|
39
|
+
results[identifier].duration_raw += example.execution_result.run_time
|
38
40
|
end
|
39
41
|
|
40
|
-
title = "Summary by #{column_name}"
|
41
|
-
|
42
42
|
headings = [
|
43
43
|
column_name, "Example count", "Duration (s)", "Average per example (s)"
|
44
44
|
]
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
example.metadata[:type] || example.file_path.slice(/.\/[^\/]+\/[^\/]+/)
|
53
|
-
end
|
54
|
-
|
55
|
-
def values_in_descending_duration(data)
|
56
|
-
data.values.sort_by(&:duration_raw).reverse_each
|
46
|
+
output_format.generate(
|
47
|
+
output: output,
|
48
|
+
title: "Summary by #{column_name}",
|
49
|
+
headings: headings,
|
50
|
+
rows: results_as_rows(results),
|
51
|
+
)
|
57
52
|
end
|
58
53
|
|
59
|
-
def
|
60
|
-
[
|
61
|
-
row.identifier,
|
62
|
-
row.example_count,
|
63
|
-
format_seconds(row.duration_raw),
|
64
|
-
format_seconds(row.avg_duration),
|
65
|
-
]
|
54
|
+
def extract_subfolder(file_path)
|
55
|
+
file_path.slice(/.\/[^\/]+\/[^\/]+/)
|
66
56
|
end
|
67
57
|
|
68
|
-
def
|
69
|
-
|
58
|
+
def results_as_rows(results)
|
59
|
+
results.values
|
60
|
+
.sort_by(&:duration_raw)
|
61
|
+
.reverse_each
|
62
|
+
.map(&:to_a)
|
70
63
|
end
|
71
64
|
|
72
|
-
def
|
73
|
-
|
74
|
-
output.puts "\n"
|
75
|
-
output.puts table
|
65
|
+
def output_format
|
66
|
+
RspecOverview::Output::Table.new
|
76
67
|
end
|
77
68
|
end
|
78
69
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "csv"
|
2
|
+
|
3
|
+
module RspecOverview
|
4
|
+
module Output
|
5
|
+
class Csv
|
6
|
+
def generate(output:, title:, headings:, rows:)
|
7
|
+
csv_string = CSV.generate(**csv_options, headers: headings) do |csv|
|
8
|
+
rows.each { |row| csv << row }
|
9
|
+
end
|
10
|
+
|
11
|
+
output.puts title
|
12
|
+
output.puts csv_string
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def csv_options
|
18
|
+
{ write_headers: true, force_quotes: true }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "terminal-table"
|
2
|
+
|
3
|
+
module RspecOverview
|
4
|
+
module Output
|
5
|
+
class Table
|
6
|
+
def generate(output:, title:, headings:, rows:)
|
7
|
+
output.puts "\n"
|
8
|
+
output.puts Terminal::Table.new(
|
9
|
+
title: title,
|
10
|
+
headings: headings,
|
11
|
+
rows: rows,
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Result
|
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_seconds
|
12
|
+
format_seconds(duration_raw / example_count)
|
13
|
+
end
|
14
|
+
|
15
|
+
def duration_seconds
|
16
|
+
format_seconds(duration_raw)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_a
|
20
|
+
[identifier, example_count, duration_seconds, avg_duration_seconds]
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def format_seconds(duration)
|
26
|
+
RSpec::Core::Formatters::Helpers.format_seconds(duration)
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_overview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oli Peate
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-core
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- ".rspec"
|
106
106
|
- ".ruby-version"
|
107
107
|
- ".travis.yml"
|
108
|
+
- CHANGELOG.md
|
108
109
|
- Gemfile
|
109
110
|
- Gemfile.lock
|
110
111
|
- LICENSE
|
@@ -114,7 +115,10 @@ files:
|
|
114
115
|
- bin/setup
|
115
116
|
- lib/rspec_overview.rb
|
116
117
|
- lib/rspec_overview/formatter.rb
|
117
|
-
- lib/rspec_overview/
|
118
|
+
- lib/rspec_overview/formatter_csv.rb
|
119
|
+
- lib/rspec_overview/output/csv.rb
|
120
|
+
- lib/rspec_overview/output/table.rb
|
121
|
+
- lib/rspec_overview/result.rb
|
118
122
|
- lib/rspec_overview/version.rb
|
119
123
|
- rspec_overview.gemspec
|
120
124
|
homepage: https://github.com/odlp/rspec_overview
|
@@ -1,14 +0,0 @@
|
|
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
|