Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7f93589
Capture actual/expected values for passing tests too
raghubetina Jul 17, 2025
4c1bb5b
Use Oj for serialization
raghubetina Jul 17, 2025
eb40007
Add automatic memory cleanup after test suite completion
raghubetina Jul 18, 2025
c7a8571
Apply StandardRB formatting and update docs
raghubetina Jul 18, 2025
3be8d4a
Use RSpec example ID for robust key generation
raghubetina Jul 18, 2025
e40d7b2
Fix passing test capture and add comprehensive tests
raghubetina Jul 18, 2025
a7672b2
Update formatter to only use Oj for expected/actual values
raghubetina Jul 18, 2025
23fdcae
Remove redundant test file
raghubetina Jul 18, 2025
763e8ce
Fix memory cleanup test to avoid self-capture
raghubetina Jul 18, 2025
534c468
Implement regex serialization with simpler inspect approach
raghubetina Jul 18, 2025
8440e07
Add special handling for Regexp serialization
raghubetina Jul 18, 2025
91cc798
Fix double-encoding issue in formatter
raghubetina Jul 18, 2025
bf1378a
Add focused tests for special serialization cases
raghubetina Jul 18, 2025
2b6e31f
Major repository cleanup
raghubetina Jul 18, 2025
a4c3f0f
Remove TODOS.md
raghubetina Jul 18, 2025
1ff3c81
Add changelog entry for version 0.6.1 and fix code style
raghubetina Jul 18, 2025
b0a9f3a
Fix predicate matcher value capture and remove double-encoding
raghubetina Jul 18, 2025
c2081a7
Gitignore parallel_tests
raghubetina Jul 18, 2025
9196f2e
Remove unused matcher-specific data extraction
raghubetina Jul 18, 2025
dfe54c5
Gitignore /amazing_print/
raghubetina Jul 18, 2025
7bfad1d
Simplify diffable check by removing unnecessary values_diffable? method
raghubetina Jul 18, 2025
82453d2
Add negated flag to capture when matchers use not_to/to_not
raghubetina Jul 18, 2025
c123ee2
Add newline at end of file
raghubetina Jul 18, 2025
75b1531
Remove outdated diffable detection tests
raghubetina Jul 18, 2025
69d640f
Simplify gem implementation
raghubetina Jul 18, 2025
eec9578
Clean up spec files
raghubetina Jul 18, 2025
7b5771e
Prepare for 0.7.0 release
raghubetina Jul 19, 2025
c553670
Remove diff stripping to be true drop-in replacement
raghubetina Jul 19, 2025
1ac7c08
Respect RSpec's color configuration for diffs
raghubetina Jul 19, 2025
9a1193f
Remove unused depth parameter from serialize_value method
raghubetina Jul 19, 2025
1a2bf31
Remove analyze_builtin_json.rb
raghubetina Jul 19, 2025
84d47a6
Add status badges to README
raghubetina Jul 19, 2025
3afe105
Update README to use double quotes per StandardRB
raghubetina Jul 21, 2025
427c114
Update CI to test Ruby 3.4 and use checkout@v4
raghubetina Jul 21, 2025
b57ce2d
Add proper punctuation to README list items
raghubetina Jul 21, 2025
4a38bbf
Update minimum Ruby version to 3.2
raghubetina Jul 21, 2025
233d972
Add spec/support directory for test fixtures
raghubetina Jul 21, 2025
f80708b
Add coverage upload to CI with unique artifact names
raghubetina Jul 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.2', '3.3', '3.4']

steps:
- uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true

- name: Run StandardRB
run: bundle exec standardrb

- name: Run tests
run: bundle exec rspec
env:
COVERAGE: true

- name: Upload coverage reports
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-report-${{ matrix.ruby-version }}
path: coverage/
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@
# Other gems for AI context
/diffy/
/super_diff/
/fuzzy_match_poc/
/oj/
/parallel_tests/
/amazing_print/

# Bundler
Gemfile.lock

# Test output files (from old complex demo)
# Test output files
*.json
enriched_output.json
standard_output.json
builtin_json_output.json
vanilla_output.json

# IDE
.idea/
Expand All @@ -36,3 +43,4 @@ standard_output.json
*.swo
*~
.DS_Store
.claude/
4 changes: 4 additions & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ ignore:
- 'spec/edge_cases_spec.rb:40'
- 'spec/safety_limits_spec.rb:52'
- 'rspec/**/*'
- 'fuzzy_match_poc/**/*'
- 'oj/**/*'
- 'diffy/**/*'
- 'super_diff/**/*'
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,40 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.7.0] - 2025-07-18

### Added
- Add `negated` flag to detect when `not_to` or `to_not` is used
- Add `passed` field to distinguish passing from failing tests in captured values

### Changed
- Major code simplification - removed unnecessary abstractions and comments
- Updated documentation to reflect actual features (removed non-existent performance limits)
- **BREAKING**: No longer removes diff from exception messages - now a true drop-in replacement

### Fixed
- Fixed spec files that were causing false CI failures
- Updated integration tests to match current behavior

### Removed
- Removed automatic diff stripping from exception messages (introduced in 0.6.1)

## [0.6.1] - 2025-07-18

### Added
- Capture expected/actual values for passing tests (not just failures)
- Memory-safe implementation with cleanup after formatter completes
- Special handling for Regexp serialization (human-readable format like `/pattern/flags`)
- Comprehensive test coverage for new features

### Fixed
- Fixed key mismatch bug between storage and retrieval of test values
- Fixed double-encoding issue in formatter that caused escaped strings in output

### Changed
- Upgraded to Oj for JSON serialization (better performance and object handling)
- Improved error handling with detailed fallback information

## [0.5.0] - 2025-06-26

### Changed
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This project creates a universal JSON output system for RSpec matchers:
- `lib/rspec/enriched_json/formatters/enriched_json_formatter.rb` - JSON formatter that outputs enriched data
- `rspec-enriched_json.gemspec` - Gem specification
- `spec/` - Test suite with integration and unit tests
- `demo_all_failures.rb` - Demo script showing various failure types
- `demo.rb` - Demo script showing various failure types
- `Gemfile` - Dependencies (rspec, standard)
- `.standard.yml` - StandardRB configuration

Expand Down
72 changes: 45 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# RSpec::EnrichedJson

[![CI](https://github.com/firstdraft/rspec-enriched_json/actions/workflows/ci.yml/badge.svg)](https://github.com/firstdraft/rspec-enriched_json/actions/workflows/ci.yml)
[![Gem Version](https://badge.fury.io/rb/rspec-enriched_json.svg)](https://badge.fury.io/rb/rspec-enriched_json)
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/standardrb/standard)

A drop-in replacement for RSpec's built-in JSON formatter that enriches the output with structured failure data. This makes it easy to programmatically analyze test results, extract expected/actual values, and build better CI/CD integrations.

## Quick Demo
Expand Down Expand Up @@ -30,7 +34,7 @@ This interactive demo script runs the same failing tests with both formatters an
Add this line to your application's Gemfile:

```ruby
gem 'rspec-enriched_json'
gem "rspec-enriched_json"
```

And then execute:
Expand Down Expand Up @@ -95,14 +99,14 @@ With this gem, you get structured data alongside the original message:

## Features

- **Drop-in replacement**: Inherits from RSpec's JsonFormatter, maintaining 100% compatibility
- **Structured data extraction**: Expected and actual values as proper JSON objects
- **Rich object support**: Arrays, hashes, and custom objects are properly serialized
- **Original message preservation**: When you override with a custom message, the original is preserved
- **Graceful degradation**: Regular exceptions (non-expectation failures) work normally
- **Enhanced metadata capture**: Test location, tags, hierarchy, and custom metadata
- **Robust error recovery**: Handles objects that fail to serialize without crashing
- **Diff information**: Includes `diffable` to help tools determine if values can be meaningfully diffed
- **Drop-in replacement**: Inherits from RSpec's JsonFormatter, maintaining 100% compatibility.
- **Structured data extraction**: Expected and actual values as proper JSON objects.
- **Rich object support**: Arrays, hashes, and custom objects are properly serialized.
- **Original message preservation**: When you override with a custom message, the original is preserved.
- **Graceful degradation**: Regular exceptions (non-expectation failures) work normally.
- **Enhanced metadata capture**: Test location, tags, hierarchy, and custom metadata.
- **Robust error recovery**: Handles objects that fail to serialize without crashing.
- **Diff information**: Includes `diffable` to help tools determine if values can be meaningfully diffed.

## Examples

Expand Down Expand Up @@ -147,36 +151,50 @@ end

## Use Cases

- **CI/CD Integration**: Parse test results to create rich error reports
- **Test Analytics**: Track which values commonly cause test failures
- **Debugging Tools**: Build tools that can display expected vs actual diffs
- **Learning Platforms**: Provide detailed feedback on why tests failed
- **CI/CD Integration**: Parse test results to create rich error reports.
- **Test Analytics**: Track which values commonly cause test failures.
- **Debugging Tools**: Build tools that can display expected vs actual diffs.
- **Learning Platforms**: Provide detailed feedback on why tests failed.

## How It Works

The gem works by:

1. Patching RSpec's expectation system to capture structured data when expectations fail
2. Extending the JsonFormatter to include this data in the JSON output
3. Maintaining full backward compatibility with existing tools
1. Patching RSpec's expectation system to capture structured data when expectations fail.
2. Extending the JsonFormatter to include this data in the JSON output.
3. Maintaining full backward compatibility with existing tools.

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.

## Performance Considerations
This project uses [StandardRB](https://github.com/standardrb/standard) for code formatting and style. Before committing:

```bash
# Check for style violations
bundle exec standardrb

# Auto-fix style violations
bundle exec standardrb --fix
```

## Additional Features

### Passing Test Value Capture
The formatter also captures expected/actual values for passing tests, useful for:
- Test analytics and insights.
- Understanding test coverage patterns.
- Debugging flaky tests.

The enriched formatter adds minimal overhead:
- Only processes failing tests (passing tests have no extra processing)
- Limits serialization depth to prevent infinite recursion
- Truncates large strings and collections to maintain reasonable output sizes
- No impact on test execution time, only on failure reporting
### Negation Detection
Tests using `not_to` or `to_not` include a `negated: true` flag in the details.

Default limits:
- Max serialization depth: 5 levels
- Max array size: 100 items
- Max hash size: 100 keys
- Max string length: 1000 characters
### Serialization
Values are serialized using [Oj](https://github.com/ohler55/oj) in object mode, providing:
- Circular reference handling.
- Proper Ruby object serialization.
- Excellent performance.
- Special handling for Regexp objects (serialized as inspect strings).

## Contributing

Expand Down
161 changes: 0 additions & 161 deletions TODOS.md

This file was deleted.

Loading
Loading