-
Notifications
You must be signed in to change notification settings - Fork 0
Fixes serialization of procs #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important
Looks good to me! 👍
Reviewed everything up to d44f8a2 in 1 minute and 23 seconds. Click for details.
- Reviewed
65lines of code in3files - Skipped
0files when reviewing. - Skipped posting
3draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. demo.rb:64
- Draft comment:
The new test "eq with proc" compares a proc (which, when called, returns 'Hello, world!') to the string 'Hello!'. If this is intended to demonstrate failure enrichment, consider clarifying the intent with a comment so readers aren’t confused by the mismatch. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%None
2. lib/rspec/enriched_json/expectation_helper_wrapper.rb:48
- Draft comment:
In the Serializer#serialize_value method, the Proc branch directly callsvalue.call. Consider checking the proc's arity (or adding documentation) to ensure it’s only used for parameterless procs, since calling a proc with arguments unintentionally could raise errors. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% The code is in a test helper that serializes values for enriched test output. The Proc handling is likely meant to evaluate lazy values during serialization. Since this is test code, any Proc arity mismatch would fail the test immediately and be obvious. The rescue block on line 53 would also catch any argument errors. The comment seems overly cautious for test tooling. I could be underestimating the impact of Proc errors in test infrastructure. Bad error messages here could make test failures harder to debug. While better error messages would be nice, the existing error handling will catch and wrap any Proc issues. The current simple implementation is adequate for test tooling. The comment raises a valid point but the suggested change isn't necessary given the context and error handling. The comment should be removed.
3. spec/oj_serialization_spec.rb:47
- Draft comment:
The test for Proc serialization cleanly verifies that a simple proc is called and its result is returned. Consider adding additional tests for cases where a proc returns a non‐string (or nil) to ensure consistent behavior across different return types. - Reason this comment was not posted:
Confidence changes required:33%<= threshold50%None
Workflow ID: wflow_IzLZHdegEgbmPcLa
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
jelaniwoods
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking at this!
I wrote a test for this that captured the behavior that happens in firstdraft / Learn codeblocks.
On main the test passes and the "actual" value is the Proc-like String, but on this branch the test fails and the "actual" value is nil. This makes me think this change isn't doing the right thing, since the test fails and the "actual" output is inaccurate.
You can see the spec I wrote here. Could you confirm if this is an issue?
|
Nice spec! I was wondering though if this would ever be our use-case: expect { require_relative("#{Dir.pwd}/spec/support/code.rb") }.to output(/Hello, world!/).to_stdoutWe tend to use I tested with the I'll have a look at this scenario anyways. I wonder if it would need a different fix. |
|
Hm maybe I misunderstood during standup but I think that we should show output when using an output matcher. Why should we not display it? |
I thought we decided to not display the "actual" results when a test passes for this matcher because by default, the matcher captures |
We do not use this matcher to capture output from the code file. We use The cases where we do use this matcher is to capture output from a method from the code file. Similar to the examples here with "print". Since we use it with I created a test that looks like this, require "rspec"
RSpec.describe "output matcher" do
it "does not capture output when requiring a file" do
expect { require_relative("#{Dir.pwd}/spec/support/code.rb") }.to output(/Hello, world!/).to_stdout
end
it "captures output from stdout" do
expect { puts "hi" }.to output("bye").to_stdout
end
endAdded it to the root directory on this repo and used |
Apologies, I missed this. I am not able to reproduce this. The actual in this example does contain the output string. I've highlighted it in the image. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important
Looks good to me! 👍
Reviewed f75641a in 23 seconds. Click for details.
- Reviewed
12lines of code in1files - Skipped
0files when reviewing. - Skipped posting
1draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. lib/rspec/enriched_json/version.rb:5
- Draft comment:
VERSION updated from 0.8.0 to 0.8.1; patch bump seems appropriate for a serialization fix. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%None
Workflow ID: wflow_OWY8jKunj5ANXUdY
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
@swaathi When I run this in the Lambda function locally with the playground, I still see the Proc in the "actual" response when the test passes. 2025-08-01.10-20-06.mp4Note: I updated the Gemfile to use |
|
Hashed this over call with Jelani. This PR works as expected. Will be merging this tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important
Looks good to me! 👍
Reviewed a6cf1a7 in 21 seconds. Click for details.
- Reviewed
12lines of code in1files - Skipped
0files when reviewing. - Skipped posting
1draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. lib/rspec/enriched_json/version.rb:5
- Draft comment:
Ensure the version bump to 0.8.2 is accompanied by appropriate changelog updates. Also verify that this update complies with the release strategy. - Reason this comment was not posted:
Confidence changes required:0%<= threshold50%None
Workflow ID: wflow_H8WUXmm47TaiyUyw
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.



Problem
Procs would be dumped to JSON (Oj) without being serialized. This would cause output issues.
Solution
Simple procs are called as part of the serialization workflow.
What used to look like before,
{ "exception": { "class": "RSpec::EnrichedJson::EnrichedExpectationNotMetError", "message": "\nexpected: \"Hello!\"\n got: #<Proc:0x000000012917a5f0 /var/folders/c5/717zkj_j50g1hdbnsb06z3rh0000gn/T/demo_test20250730-63756-o2wass.rb:44>\n\n(compared using ==)\n" }, "details": { "expected": "\"Hello!\"", "actual": "{\"^o\":\"Proc\",\"^i\":1}", "original_message": null, "matcher_name": "RSpec::Matchers::BuiltIn::Eq", "diffable": true, "negated": false } }Now looks like this,
{ "exception": { "class": "RSpec::EnrichedJson::EnrichedExpectationNotMetError", "message": "\nexpected: \"Hello!\"\n got: #<Proc:0x000000012514c410 /var/folders/c5/717zkj_j50g1hdbnsb06z3rh0000gn/T/demo_test20250730-66617-k5sedp.rb:44>\n\n(compared using ==)\n" }, "details": { "expected": "\"Hello!\"", "actual": "Hello, world!", "original_message": null, "matcher_name": "RSpec::Matchers::BuiltIn::Eq", "diffable": true, "negated": false } }Important
Fixes
Procserialization by calling them during JSON serialization, adds tests, and updates version to0.8.2.Procobjects are now called during serialization inserialize_value()inexpectation_helper_wrapper.rb.Procserialization inoj_serialization_spec.rb.Procequality matcher indemo.rb.0.8.2inversion.rb.This description was created by
for a6cf1a7. You can customize this summary. It will automatically update as commits are pushed.