rspec_overview 0.1.1 → 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: bf40c3329b0d98739b0e00a6a202bb23d9b5c205
4
- data.tar.gz: e34c2e84a63d87523a889ba3fa2ad13d8b5cb542
3
+ metadata.gz: 91ecf4bf56b43ba4727d25899adcc5523827de5c
4
+ data.tar.gz: 3b280c205f00035b4455644041daf5bbdb73fd55
5
5
  SHA512:
6
- metadata.gz: 71f0ab02f6846a6a0ca731ace4b7d90ab0e6ffb6b4f2d26914399b736cbb7fff7307317732b13275af9281c5284a702261660c18cc7ab770fcd71437040208c9
7
- data.tar.gz: bf7efbaf8b0408422fab6844252aced0686c48d5b81b0b7f1db5472c4dffbdaa5841c05b7d49968d4002508c4886968b6caff5d09d5ff87875b6637fda4484a6
6
+ metadata.gz: 48e0d3b44f2cd9e4d71c8978df408e884560123c1c51bf053f316f2f8a3385de27a6f6eebdcc836b1bda9571a3bb041b6c1ae9e9f5d3989bccae9a2a22f87119
7
+ data.tar.gz: c524cde83bcf2ba4c857787132c1d7d685b10a32d1f6afb0cb336f2c6add205bb8fb7b96c894a0f2abac580b3011172bb29093ddd767fced9e1832a2b2c465a2
data/.rspec CHANGED
@@ -1,4 +1,3 @@
1
1
  --color
2
2
  --require spec_helper
3
3
  --format progress
4
- --format RspecOverview::Formatter
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## v0.2.0
4
+ - Add CSV format support
5
+
6
+ ## v0.1.1
7
+ - Tweak style of table titles
8
+
9
+ ## v0.1.0
10
+ - Initial release
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec_overview (0.1.1)
4
+ rspec_overview (0.2.0)
5
5
  rspec-core (~> 3.0)
6
6
  terminal-table (~> 1.6)
7
7
 
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 an
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 meta-type (feature, model, controller)?
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
- task default: :spec
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]
@@ -1,4 +1,5 @@
1
1
  require "rspec_overview/formatter"
2
+ require "rspec_overview/formatter_csv"
2
3
  require "rspec_overview/version"
3
4
 
4
5
  module RspecOverview
@@ -1,6 +1,6 @@
1
1
  require "rspec/core"
2
- require "terminal-table"
3
- require_relative "result_row"
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, &method(:type_or_subfolder))
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
- data = {}
33
+ results = {}
32
34
 
33
35
  examples.each do |example|
34
36
  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
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
- rows = values_in_descending_duration(data).map(&method(:as_table_row))
47
-
48
- print_table(title: title, headings: headings, rows: rows)
49
- end
50
-
51
- def type_or_subfolder(example)
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 as_table_row(row)
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 format_seconds(duration)
69
- RSpec::Core::Formatters::Helpers.format_seconds(duration)
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 print_table(title:, headings:, rows:)
73
- table = Terminal::Table.new(title: title, headings: headings, rows: rows)
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,13 @@
1
+ require_relative "output/csv"
2
+
3
+ module RspecOverview
4
+ class FormatterCsv < Formatter
5
+ RSpec::Core::Formatters.register self, :dump_summary
6
+
7
+ private
8
+
9
+ def output_format
10
+ RspecOverview::Output::Csv.new
11
+ end
12
+ end
13
+ 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
@@ -1,3 +1,3 @@
1
1
  module RspecOverview
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  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.1.1
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-01-28 00:00:00.000000000 Z
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/result_row.rb
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