rspec-enriched_json 0.2.0 → 0.3.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 +4 -4
- data/README.md +5 -5
- data/lib/rspec/enriched_json/enriched_expectation_not_met_error.rb +3 -3
- data/lib/rspec/enriched_json/expectation_helper_wrapper.rb +2 -2
- data/lib/rspec/enriched_json/formatters/enriched_json_formatter.rb +8 -8
- data/lib/rspec/enriched_json/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae7cf3c69f8919e4810f402f0f34fa88bb69affbadcf6f0f9ec0f1150a4bd184
|
4
|
+
data.tar.gz: 4102bf64a17bf2a5d925814f0cb63cb749c14a41a1c8df099a85c1c636b1737c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 389db8798122e41f7bceacd58fe4532b2856b3795b96f540915fbe40f2dab9e6892b1dd7b790c7b04254db450d0696188ef3522d6971309808cf15eaa7bcb63b
|
7
|
+
data.tar.gz: 2d1a5f679578f2621bc54e9a60199ba167e5a7e5bb03fb027aaefdb0183d420e10d9e14abc1879e7ab43f04215348a823f732043e48feeb8ae2f898a029a2336
|
data/README.md
CHANGED
@@ -83,7 +83,7 @@ With this gem, you get structured data alongside the original message:
|
|
83
83
|
"message": "\nexpected: \"Hello, Ruby!\"\n got: \"Hello, World!\"\n\n(compared using ==)\n",
|
84
84
|
"backtrace": ["./spec/example_spec.rb:5:in `block (2 levels) in <top (required)>'"]
|
85
85
|
},
|
86
|
-
"
|
86
|
+
"enriched_with": {
|
87
87
|
"expected": "Hello, Ruby!",
|
88
88
|
"actual": "Hello, World!",
|
89
89
|
"matcher_name": "RSpec::Matchers::BuiltIn::Eq",
|
@@ -111,20 +111,20 @@ With this gem, you get structured data alongside the original message:
|
|
111
111
|
### Simple Values
|
112
112
|
```ruby
|
113
113
|
expect(1 + 1).to eq(3)
|
114
|
-
#
|
114
|
+
# enriched_with: { "expected": 3, "actual": 2 }
|
115
115
|
```
|
116
116
|
|
117
117
|
### Collections
|
118
118
|
```ruby
|
119
119
|
expect([1, 2, 3]).to eq([1, 2, 4])
|
120
|
-
#
|
120
|
+
# enriched_with: { "expected": [1, 2, 4], "actual": [1, 2, 3] }
|
121
121
|
```
|
122
122
|
|
123
123
|
### Complex Objects
|
124
124
|
```ruby
|
125
125
|
Product = Struct.new(:name, :price)
|
126
126
|
expect(Product.new("Laptop", 999)).to eq(Product.new("Laptop", 899))
|
127
|
-
#
|
127
|
+
# enriched_with includes class info and struct values
|
128
128
|
```
|
129
129
|
|
130
130
|
### Custom Messages
|
@@ -132,7 +132,7 @@ expect(Product.new("Laptop", 999)).to eq(Product.new("Laptop", 899))
|
|
132
132
|
expect(balance).to be >= required,
|
133
133
|
"Insufficient funds: $#{balance} available, $#{required} required"
|
134
134
|
# exception.message: "Insufficient funds: $50 available, $100 required"
|
135
|
-
#
|
135
|
+
# enriched_with: { "original_message": "expected: >= 100\n got: 50" }
|
136
136
|
```
|
137
137
|
|
138
138
|
### Metadata Capture
|
@@ -6,11 +6,11 @@ module RSpec
|
|
6
6
|
module EnrichedJson
|
7
7
|
# Custom exception that carries structured data alongside the message
|
8
8
|
class EnrichedExpectationNotMetError < RSpec::Expectations::ExpectationNotMetError
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :enriched_with
|
10
10
|
|
11
|
-
def initialize(message,
|
11
|
+
def initialize(message, enriched_with = {})
|
12
12
|
super(message)
|
13
|
-
@
|
13
|
+
@enriched_with = enriched_with
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -106,7 +106,7 @@ module RSpec
|
|
106
106
|
actual_raw = extract_value(matcher, :actual)
|
107
107
|
|
108
108
|
# Collect structured data
|
109
|
-
|
109
|
+
enriched_with = {
|
110
110
|
expected: Serializer.serialize_value(expected_raw),
|
111
111
|
actual: Serializer.serialize_value(actual_raw),
|
112
112
|
original_message: original_message, # Only populated when custom message overrides it
|
@@ -117,7 +117,7 @@ module RSpec
|
|
117
117
|
}
|
118
118
|
|
119
119
|
# Raise new exception with data attached
|
120
|
-
raise EnrichedExpectationNotMetError.new(e.message,
|
120
|
+
raise EnrichedExpectationNotMetError.new(e.message, enriched_with)
|
121
121
|
end
|
122
122
|
|
123
123
|
private
|
@@ -25,8 +25,8 @@ module RSpec
|
|
25
25
|
}
|
26
26
|
|
27
27
|
# Add structured data if available
|
28
|
-
if e.is_a?(RSpec::EnrichedJson::EnrichedExpectationNotMetError) && e.
|
29
|
-
hash[:
|
28
|
+
if e.is_a?(RSpec::EnrichedJson::EnrichedExpectationNotMetError) && e.enriched_with
|
29
|
+
hash[:enriched_with] = safe_structured_data(e.enriched_with)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -84,13 +84,13 @@ module RSpec
|
|
84
84
|
hierarchy
|
85
85
|
end
|
86
86
|
|
87
|
-
def safe_structured_data(
|
87
|
+
def safe_structured_data(enriched_with)
|
88
88
|
{
|
89
|
-
expected: safe_serialize(
|
90
|
-
actual: safe_serialize(
|
91
|
-
matcher_name:
|
92
|
-
original_message:
|
93
|
-
diff_info:
|
89
|
+
expected: safe_serialize(enriched_with[:expected]),
|
90
|
+
actual: safe_serialize(enriched_with[:actual]),
|
91
|
+
matcher_name: enriched_with[:matcher_name],
|
92
|
+
original_message: enriched_with[:original_message],
|
93
|
+
diff_info: enriched_with[:diff_info]
|
94
94
|
}.compact
|
95
95
|
end
|
96
96
|
|