omoteura-rspec 0.1.0 → 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
  SHA256:
3
- metadata.gz: 934b8861409e26c228eb9f4644637078de2e9526c83c935f209db204ff527e86
4
- data.tar.gz: 69aa7c639adc67f991013cd40728d346c5d95b80cdc5a9a4ad49f26b0fe8a735
3
+ metadata.gz: acd5916d66779c426d9b0598f24ca7b19e63a3c0f8a7091af65045153b8f9106
4
+ data.tar.gz: ef8c6d830f4d7c5dad0cd0a0ce5ba8cd5163d7d00b82cb1356b0dcc692ab7ab5
5
5
  SHA512:
6
- metadata.gz: 2d759a5621411ef3bede239c38d030db87b7dbc95ddd48c38ff0f89cfbb3987878a089a3ea07bd3d2d5a2e90a435d653605efa7c9d77cbeece3971bf2cc5a575
7
- data.tar.gz: ca823d019e86da98da3f37403ee12e600f12d8da1110b7726cdfc3e47215985cb70ad572a05dcdd581d88f91d694ba53933d28d86dc8e1d5f7f72fb76f26b2eb
6
+ metadata.gz: 1356d1c17e2c0d4159dbedb2fb0ae2e236772a83d0e9f4d2ae593b8c5f596ea03e227e6e5326c6eed0eac00211b038ab4ffd11710c3e5acaa7bdeeef6a801ef6
7
+ data.tar.gz: bdb2085aadbd62552850d6a8353463e756395dba94050c3ae07711e5a0f892908e14a9817a05d991614bf5430c28ab4e3952bebf56caa7aaebf1cd4dbcd2e5c5
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "coverage"
4
- require "json"
5
- require "time"
6
3
  require "rspec/core"
4
+ require "omoteura/results_file"
7
5
 
8
6
  module Omoteura
9
7
  module RSpec
@@ -21,10 +19,7 @@ module Omoteura
21
19
  # tell which methods the tests called. The formatter never starts
22
20
  # coverage itself: a coverage tool starting after it would fail.
23
21
  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)/}
22
+ FORMAT_VERSION = ResultsFile::FORMAT_VERSION
28
23
 
29
24
  ::RSpec::Core::Formatters.register self, :example_passed, :example_failed, :example_pending, :close
30
25
 
@@ -39,7 +34,7 @@ module Omoteura
39
34
 
40
35
  def example_failed(notification)
41
36
  exception = notification.example.execution_result.exception
42
- @examples << example_data(notification.example, "failed", message: exception && plain(exception.message))
37
+ @examples << example_data(notification.example, "failed", message: exception && ResultsFile.plain(exception.message))
43
38
  end
44
39
 
45
40
  def example_pending(notification)
@@ -47,11 +42,7 @@ module Omoteura
47
42
  end
48
43
 
49
44
  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")
45
+ @output.write(ResultsFile.generate(@examples))
55
46
  end
56
47
 
57
48
  private
@@ -66,36 +57,6 @@ module Omoteura
66
57
  message: message
67
58
  }
68
59
  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
60
  end
100
61
  end
101
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omoteura-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - KAIBYAKU K.K
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.1.0
18
+ version: 0.2.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 0.1.0
25
+ version: 0.2.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec-core
28
28
  requirement: !ruby/object:Gem::Requirement