omoteura-rspec 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 934b8861409e26c228eb9f4644637078de2e9526c83c935f209db204ff527e86
4
+ data.tar.gz: 69aa7c639adc67f991013cd40728d346c5d95b80cdc5a9a4ad49f26b0fe8a735
5
+ SHA512:
6
+ metadata.gz: 2d759a5621411ef3bede239c38d030db87b7dbc95ddd48c38ff0f89cfbb3987878a089a3ea07bd3d2d5a2e90a435d653605efa7c9d77cbeece3971bf2cc5a575
7
+ data.tar.gz: ca823d019e86da98da3f37403ee12e600f12d8da1110b7726cdfc3e47215985cb70ad572a05dcdd581d88f91d694ba53933d28d86dc8e1d5f7f72fb76f26b2eb
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 KAIBYAKU K.K
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "coverage"
4
+ require "json"
5
+ require "time"
6
+ require "rspec/core"
7
+
8
+ module Omoteura
9
+ module RSpec
10
+ # Writes every example's result as JSON for the editor to color linked
11
+ # shapes with. Use it next to a normal formatter:
12
+ #
13
+ # --format progress
14
+ # --format Omoteura::RSpec::Formatter --out tmp/omoteura/results.json
15
+ #
16
+ # RSpec loads this file from the class name by itself, so .rspec needs
17
+ # no --require line.
18
+ #
19
+ # When something already measures coverage, as SimpleCov does, the lines
20
+ # of the project's own code that ran are recorded too, so the editor can
21
+ # tell which methods the tests called. The formatter never starts
22
+ # coverage itself: a coverage tool starting after it would fail.
23
+ class Formatter
24
+ FORMAT_VERSION = 1
25
+ ANSI_ESCAPE = /\e\[[0-9;]*m/
26
+ # Code that is not the project's own, or is the tests themselves.
27
+ NOT_PROJECT_CODE = %r{\A(?:spec|test|vendor|tmp|node_modules)/}
28
+
29
+ ::RSpec::Core::Formatters.register self, :example_passed, :example_failed, :example_pending, :close
30
+
31
+ def initialize(output)
32
+ @output = output
33
+ @examples = []
34
+ end
35
+
36
+ def example_passed(notification)
37
+ @examples << example_data(notification.example, "passed")
38
+ end
39
+
40
+ def example_failed(notification)
41
+ exception = notification.example.execution_result.exception
42
+ @examples << example_data(notification.example, "failed", message: exception && plain(exception.message))
43
+ end
44
+
45
+ def example_pending(notification)
46
+ @examples << example_data(notification.example, "pending", message: notification.example.execution_result.pending_message)
47
+ end
48
+
49
+ def close(_notification)
50
+ data = {version: FORMAT_VERSION, generated_at: Time.now.utc.iso8601, summary: summary, examples: @examples}
51
+ executed = executed_lines
52
+ data[:executed_lines] = executed if executed
53
+ @output.write(JSON.pretty_generate(data))
54
+ @output.write("\n")
55
+ end
56
+
57
+ private
58
+
59
+ def example_data(example, status, message: nil)
60
+ {
61
+ id: example.id,
62
+ file_path: example.metadata[:file_path].delete_prefix("./"),
63
+ line_number: example.metadata[:line_number],
64
+ full_description: example.full_description,
65
+ status: status,
66
+ message: message
67
+ }
68
+ end
69
+
70
+ # Line numbers that ran, by file relative to the working directory, or
71
+ # nil when coverage is not being measured.
72
+ def executed_lines
73
+ return nil unless ::Coverage.running?
74
+
75
+ root = File.join(Dir.pwd, "")
76
+ ::Coverage.peek_result.each_with_object({}) do |(path, counts), executed|
77
+ next unless path.start_with?(root) && path.end_with?(".rb")
78
+
79
+ relative = path.delete_prefix(root)
80
+ next if relative.match?(NOT_PROJECT_CODE)
81
+
82
+ # Hash for Coverage.start(lines: true), as SimpleCov uses; an
83
+ # Array of line counts for the older Coverage.start.
84
+ lines = counts.is_a?(Hash) ? counts[:lines] : counts
85
+ next unless lines
86
+
87
+ executed[relative] = lines.each_index.select { |i| lines[i]&.positive? }.map { |i| i + 1 }
88
+ end
89
+ end
90
+
91
+ def summary
92
+ counts = @examples.map { |e| e[:status] }.tally
93
+ {examples: @examples.size, failures: counts.fetch("failed", 0), pending: counts.fetch("pending", 0)}
94
+ end
95
+
96
+ def plain(text)
97
+ text.gsub(ANSI_ESCAPE, "")
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omoteura/core"
4
+
5
+ module Omoteura
6
+ module RSpec
7
+ end
8
+ end
9
+
10
+ require "omoteura/rspec/formatter"
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omoteura-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - KAIBYAKU K.K
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: omoteura-core
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - '='
17
+ - !ruby/object:Gem::Version
18
+ version: 0.1.0
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - '='
24
+ - !ruby/object:Gem::Version
25
+ version: 0.1.0
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec-core
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '3.12'
33
+ - - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: '4'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '3.12'
43
+ - - "<"
44
+ - !ruby/object:Gem::Version
45
+ version: '4'
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - LICENSE
51
+ - lib/omoteura/rspec.rb
52
+ - lib/omoteura/rspec/formatter.rb
53
+ homepage: https://github.com/kaibyaku-jp/omoteura
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ source_code_uri: https://github.com/kaibyaku-jp/omoteura
58
+ changelog_uri: https://github.com/kaibyaku-jp/omoteura/blob/main/CHANGELOG.md
59
+ rubygems_mfa_required: 'true'
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '3.4'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.6.9
75
+ specification_version: 4
76
+ summary: RSpec spec analysis and result formatter for Omoteura
77
+ test_files: []