rspec-enriched_json 0.8.0 → 0.8.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: 840927ecfa09fc825a0f9656e11b7e10c4f4f5b368c144e5536dfa0595714192
4
- data.tar.gz: 5616ee6697817e0321938e53ae71410c110d9dc13bbd697dd0f2e974325efa7e
3
+ metadata.gz: 394af05d97929e94bd1c9b39aead58ab1254b7208f2f6be5c4dc07cb761d6d3a
4
+ data.tar.gz: c23222189bcb9497bf8201847968136ec9a5323e1db191b0d4548e261688b7b2
5
5
  SHA512:
6
- metadata.gz: ea0dcb189eafca59326cab5550444fe262f4475575b0860381c203dc3c16886fb7c4244df7123bdd854c398ad0b47b4fdaf0d523425fcba843845ea1f72f3eb0
7
- data.tar.gz: d8c279936a9641ea12377e4952c747bc9da60abaa15542bd973143180c1249bbcb8504e161411cb78a5cb07cd406c96612ce2ed24a00bfd695c268e24c5ea799
6
+ metadata.gz: ca7f20e71192f8dae52d73544b7971ccafacc425c30aa4c98ca33cc45e9d0c8723d8e0b7480aff717da4a6c8dc106229957f0d97968117593faacc2f8812ea06
7
+ data.tar.gz: d90481ce505fd5badf38037ef7610d1215a5959472460f0a43d2f1d9ad027c158c51fc14f0d34f4cc1a291eabc583f09654706cc4b73f088e11a0f59be0ad73f
@@ -45,6 +45,8 @@ module RSpec
45
45
  def serialize_value(value)
46
46
  if value.is_a?(Regexp)
47
47
  return Oj.dump(value.inspect, mode: :compat)
48
+ elsif value.is_a?(Proc)
49
+ return value.call
48
50
  end
49
51
 
50
52
  Oj.dump(value, OJ_OPTIONS)
@@ -7,8 +7,20 @@ module RSpec
7
7
  module EnrichedJson
8
8
  module Formatters
9
9
  class EnrichedJsonFormatter < RSpec::Core::Formatters::JsonFormatter
10
+ ANSI_COLOR_REGEX = /\e\[[0-9;]*[mGKHF]/
11
+ EXCEPTION_DETECTOR_REGEX = /(Exception|Error|undefined method|uninitialized constant)/
12
+ PATH_AND_LINE_NUMBER_REGEX = /#?(?<path>.+?):(?<line_number>\d+)/
13
+ EXCEPTION_CLASS_AND_MESSAGE_REGEX = /^(?<exception_class>[A-Z]\w*Error|Exception):$\n(?<exception_message>(?<extra>^\s\s.*\n?)+)/
14
+
10
15
  RSpec::Core::Formatters.register self, :message, :dump_summary, :dump_profile, :stop, :seed, :close
11
16
 
17
+ def initialize(output)
18
+ super
19
+ @output_hash = {
20
+ errors: []
21
+ }
22
+ end
23
+
12
24
  def stop(group_notification)
13
25
  @output_hash[:examples] = group_notification.notifications.map do |notification|
14
26
  format_example(notification.example).tap do |hash|
@@ -36,6 +48,30 @@ module RSpec
36
48
  end
37
49
  end
38
50
 
51
+ def message(notification)
52
+ super
53
+
54
+ if notification.message.match?(EXCEPTION_DETECTOR_REGEX)
55
+ clean_message = notification.message.gsub(ANSI_COLOR_REGEX, "")
56
+
57
+ error_info = {
58
+ message: clean_message
59
+ }
60
+
61
+ if (match = clean_message.match(PATH_AND_LINE_NUMBER_REGEX))
62
+ error_info[:path] = match.named_captures["path"]
63
+ error_info[:line_number] = match.named_captures["line_number"]
64
+ end
65
+
66
+ if (match = clean_message.match(EXCEPTION_CLASS_AND_MESSAGE_REGEX))
67
+ error_info[:exception_class] = match.named_captures["exception_class"]
68
+ error_info[:exception_message] = match.named_captures["exception_message"]
69
+ end
70
+
71
+ @output_hash[:errors] << error_info
72
+ end
73
+ end
74
+
39
75
  private
40
76
 
41
77
  def add_metadata(hash, example)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module EnrichedJson
5
- VERSION = "0.8.0"
5
+ VERSION = "0.8.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-enriched_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raghu Betina