rspec_logfmt_formatter 0.0.1 → 0.0.2

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
  SHA256:
3
- metadata.gz: 211c7cbe090b13a9762b825d0cfeb2aecb4e43f2d44037147efd158883144565
4
- data.tar.gz: 46c20ba3d51965bdd6f8ceee5bdf4a3f14d9efaf3af5efb73f154ac675a55057
3
+ metadata.gz: c2379f5938b480ca7b7f9506060f99a482b07d3144644750b6d976a665f5c774
4
+ data.tar.gz: 18029228ddc06f01d38dbe2e89c480b9411ba8e6b4bf2bc474ff359df6256273
5
5
  SHA512:
6
- metadata.gz: 46ae8acd77714be862c4da0455cb5c553dbcc1fb05747e158f633323aa5246d46e72154ec0a346e042b735a5b1d645503a0ce5103242997116205ecf2bb86cf6
7
- data.tar.gz: a95b1e04e094ae0067baeacffa3cce3a34a8097014c9066ebedbc6575999d22a957d0c7484981c73c3bb11bdc478134ea179f5386b6d357a6a430528e9fb1c67
6
+ metadata.gz: 55f9cede488a1b1ac881bd7e788217bca1f7e5914e28d5dc7a8ea415e923665a5509195cd96065b2ff1a06eb374dbead8c47c87b35fc029da0da0c96cdd3a3c8
7
+ data.tar.gz: 05b94d45666d2ac8b9c0955754741db5c3064b9ece162e2f502fed9c7f7b44174d91590f51c469ba5752e0aad865efc044fefe39029deea4097c2b52588ca615
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # RSpec logfmt Formatter
2
2
 
3
3
  [![CircleCI](https://circleci.com/gh/carwow/rspec_logfmt_formatter/tree/master.svg?style=svg)](https://circleci.com/gh/carwow/rspec_logfmt_formatter/tree/master)
4
+ [![Gem Version](https://badge.fury.io/rb/rspec_logfmt_formatter.svg)](https://badge.fury.io/rb/rspec_logfmt_formatter)
4
5
 
5
- [RSpec][rspec] 3 results in the [logfmt][logfmt] format that you can push to you observability tool such as [Honeycomb][honeycomb]
6
+ [RSpec][rspec] 3 results in the [logfmt][logfmt] format that you can push to your observability tool such as [Honeycomb][honeycomb]
6
7
 
7
8
  [rspec]: http://rspec.info/
8
9
  [logfmt]: https://brandur.org/logfmt
@@ -11,19 +12,15 @@
11
12
  ## Usage
12
13
 
13
14
  Install the gem:
14
- <details>
15
- <summary>WIP</summary>
16
15
 
17
16
  ```sh
18
17
  gem install rspec_logfmt_formatter
19
18
  ```
20
19
 
21
- </details>
22
-
23
20
  Use it:
24
21
 
25
22
  ```sh
26
- rspec --format RspecLogfmtFormatter::Formatter --out rspec.txt
23
+ rspec --format RspecLogfmtFormatter --out rspec.txt
27
24
  ```
28
25
 
29
26
  You'll get a file `rspec.txt` with your results in it.
@@ -31,7 +28,7 @@ You'll get a file `rspec.txt` with your results in it.
31
28
  You can use it in combination with other [formatters][rspec-formatters], too:
32
29
 
33
30
  ```sh
34
- rspec --format progress --format RspecLogfmtFormatter::Formatter --out rspec.txt
31
+ rspec --format progress --format RspecLogfmtFormatter --out rspec.txt
35
32
  ```
36
33
 
37
34
  [rspec-formatters]: https://relishapp.com/rspec/rspec-core/v/3-6/docs/formatters
@@ -50,32 +47,51 @@ end
50
47
  Put the same arguments as the commands above in [your `.rspec`][rspec-file]:
51
48
 
52
49
  ```sh
53
- --format RspecLogfmtFormatter::Formatter
54
- --out rspec.txt
50
+ --format RspecLogfmtFormatter --out rspec.txt
55
51
  ```
56
52
  [bundler]: https://bundler.io
57
53
  [rspec-file]: https://relishapp.com/rspec/rspec-core/v/3-6/docs/configuration/read-command-line-configuration-options-from-files
58
54
 
59
55
  ### Parallel tests
60
56
 
61
- For use with `parallel_tests`, add `$TEST_ENV_NUMBER` in the output file option (in `.rspec` or `.rspec_parallel`) to avoid concurrent process write conflicts.
57
+ You can sum repeated values in one file using `rspec_logfmt_formatter_collate rspec.txt`.
62
58
 
63
- ```sh
64
- --format RspecLogfmtFormatter::Formatter
65
- --out tmp/rspec<%= ENV["TEST_ENV_NUMBER"] %>.txt
59
+ It will rewrite a file like:
60
+
61
+ ```
62
+ tests.count="3"
63
+ tests.count="1"
64
+ ```
65
+
66
+ into:
67
+
68
+ ```
69
+ tests.count="4"
66
70
  ```
67
71
 
68
72
  ### How to push to Honeycomb
69
73
 
70
- TODO
74
+ There are many ways you can push this to honeycomb. One way is to use the [buildevents][buildevents] binary. Then output your spec output to `BUILDEVENT_FILE` e.g.
75
+
76
+ ```sh
77
+ bundle exec rspec --format RspecLogfmtFormatter --out $BUILDEVENT_FILE
78
+ ```
79
+
80
+ [buildevents]: https://github.com/honeycombio/buildevents
71
81
 
72
82
  ## Development
73
83
 
74
- TODO
84
+ Pull the repo and run `bundle install`, the specs are run with `bundle exec rspec` and make sure to read the [CONTRIBUTING.md](./CONTRIBUTING.md).
75
85
 
76
86
  ## Releasing
77
87
 
78
- TODO
88
+ Currently this is a manual process and can only be run by a carwow developer.
89
+
90
+ 1. Ensure your `~/.gem/credentials` are correct
91
+ 2. Update the [CHANGELOG.md](./CHANGELOG.md)
92
+ 3. Update the [version.rb](./lib/rspec_logfmt_formatter/version.rb)
93
+ 4. Run `bundle exec rake upload`
94
+ 5. Check the tag was pushed and the new version was released
79
95
 
80
96
  ## License
81
97
 
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rspec_logfmt_formatter"
4
+
5
+ file = ARGV.first
6
+ out = -> { file ? File.new(file, "w") : $stdout }
7
+
8
+ ARGF.read
9
+ .then { |input| RspecLogfmtFormatter.collate input }
10
+ .then { |collated| out.call.puts collated }
@@ -1,2 +1,42 @@
1
- require 'rspec_logfmt_formatter/formatter'
2
- require 'rspec_logfmt_formatter/version'
1
+ require "rspec/core"
2
+ require "rspec/core/formatters/base_formatter"
3
+
4
+ class RspecLogfmtFormatter < RSpec::Core::Formatters::BaseFormatter
5
+ RSpec::Core::Formatters.register self, :dump_summary
6
+
7
+ def self.collate(input)
8
+ collated = {}
9
+
10
+ input.scan(/(tests\.\w+)="(\d+)"/) do |key, value|
11
+ collated[key] = collated[key].to_i + value.to_i
12
+ end
13
+
14
+ collated.map { |key, value| "#{key}=\"#{value}\"" }.join("\n")
15
+ end
16
+
17
+ def initialize(...)
18
+ super
19
+ @retries = []
20
+ end
21
+
22
+ def dump_summary(notification)
23
+ @summary = notification
24
+ logfmt_dump
25
+ end
26
+
27
+ def retry(example)
28
+ @retries << example
29
+ end
30
+
31
+ private
32
+
33
+ def logfmt_dump
34
+ output.puts [
35
+ %(tests.count="#{@summary.example_count}"),
36
+ %(tests.skipped="#{@summary.pending_count}"),
37
+ %(tests.failures="#{@summary.failure_count}"),
38
+ %(tests.errors="#{@summary.errors_outside_of_examples_count}"),
39
+ %(tests.retries="#{@retries.count}")
40
+ ].join("\n")
41
+ end
42
+ end
metadata CHANGED
@@ -1,106 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_logfmt_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Vickerstaff
8
- autorequire:
9
- bindir: bin
8
+ bindir: exe
10
9
  cert_chain: []
11
- date: 2022-01-19 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: carwow_rubocop
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '='
32
- - !ruby/object:Gem::Version
33
- version: 3.4.4
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '='
39
- - !ruby/object:Gem::Version
40
- version: 3.4.4
41
- - !ruby/object:Gem::Dependency
42
- name: pry
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec_junit_formatter
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec-retry
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
12
  - !ruby/object:Gem::Dependency
98
13
  name: rspec-core
99
14
  requirement: !ruby/object:Gem::Requirement
100
15
  requirements:
101
16
  - - ">="
102
17
  - !ruby/object:Gem::Version
103
- version: '2'
18
+ version: '3.6'
104
19
  - - "<"
105
20
  - !ruby/object:Gem::Version
106
21
  version: '4'
@@ -110,27 +25,26 @@ dependencies:
110
25
  requirements:
111
26
  - - ">="
112
27
  - !ruby/object:Gem::Version
113
- version: '2'
28
+ version: '3.6'
114
29
  - - "<"
115
30
  - !ruby/object:Gem::Version
116
31
  version: '4'
117
32
  description: ''
118
33
  email:
119
34
  - developers@carwow.co.uk
120
- executables: []
35
+ executables:
36
+ - rspec_logfmt_formatter_collate
121
37
  extensions: []
122
38
  extra_rdoc_files: []
123
39
  files:
124
40
  - LICENSE
125
41
  - README.md
42
+ - exe/rspec_logfmt_formatter_collate
126
43
  - lib/rspec_logfmt_formatter.rb
127
- - lib/rspec_logfmt_formatter/formatter.rb
128
- - lib/rspec_logfmt_formatter/version.rb
129
44
  homepage: https://github.com/carwow/rspec_logfmt_formatter
130
45
  licenses:
131
46
  - MIT
132
47
  metadata: {}
133
- post_install_message:
134
48
  rdoc_options: []
135
49
  require_paths:
136
50
  - lib
@@ -138,15 +52,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
52
  requirements:
139
53
  - - ">="
140
54
  - !ruby/object:Gem::Version
141
- version: 2.7.0
55
+ version: '3.2'
142
56
  required_rubygems_version: !ruby/object:Gem::Requirement
143
57
  requirements:
144
58
  - - ">="
145
59
  - !ruby/object:Gem::Version
146
- version: 2.0.0
60
+ version: '0'
147
61
  requirements: []
148
- rubygems_version: 3.1.4
149
- signing_key:
62
+ rubygems_version: 3.6.7
150
63
  specification_version: 4
151
64
  summary: RSpec formatter that honeycomb can read
152
65
  test_files: []
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rspec/core'
4
- require 'rspec/core/formatters/base_formatter'
5
-
6
- module RspecLogfmtFormatter
7
- class Formatter < RSpec::Core::Formatters::BaseFormatter
8
- RSpec::Core::Formatters.register self,
9
- :start,
10
- :stop,
11
- :dump_summary
12
-
13
- def start(notification)
14
- @start_notification = notification
15
- @started = Time.now
16
- @retries = []
17
- super
18
- end
19
-
20
- def stop(notification)
21
- @examples_notification = notification
22
- end
23
-
24
- def dump_summary(notification)
25
- @summary_notification = notification
26
- fmt_dump
27
- end
28
-
29
- def retry(example)
30
- @retries << example
31
- end
32
-
33
- private
34
-
35
- attr_reader :started, :retries
36
-
37
- def example_count
38
- @summary_notification.example_count
39
- end
40
-
41
- def pending_count
42
- @summary_notification.pending_count
43
- end
44
-
45
- def failure_count
46
- @summary_notification.failure_count
47
- end
48
-
49
- def duration
50
- @summary_notification.duration
51
- end
52
-
53
- def error_count
54
- if @summary_notification.respond_to?(:errors_outside_of_examples_count)
55
- @summary_notification.errors_outside_of_examples_count
56
- else
57
- 0
58
- end
59
- end
60
-
61
- # rubocop:disable Metrics/AbcSize
62
- def fmt_dump
63
- output << %( tests.name="rspec#{ENV['TEST_ENV_NUMBER']}")
64
- output << %( tests.count="#{example_count}")
65
- output << %( tests.skipped="#{pending_count}")
66
- output << %( tests.failures="#{failure_count}")
67
- output << %( tests.errors="#{error_count}")
68
- output << %( tests.retries.count="#{retries.size}")
69
- end
70
- # rubocop:enable Metrics/AbcSize
71
- end
72
- end
@@ -1,3 +0,0 @@
1
- module RspecLogfmtFormatter
2
- VERSION = '0.0.1'.freeze
3
- end