Skip to content

Commit de59572

Browse files
authored
Fixes serialization of procs (#15)
1 parent bdbe61c commit de59572

4 files changed

Lines changed: 17 additions & 3 deletions

File tree

demo.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
it "eq with nil" do
6161
expect("Alice").to eq(nil)
6262
end
63+
64+
it "eq with proc" do
65+
helloworld = proc { "Hello, world!" }
66+
expect(helloworld).to eq("Hello!")
67+
end
6368
6469
# Identity Matchers
6570
it "be (object identity)" do
@@ -394,7 +399,7 @@ def initialize
394399

395400
# Group examples by category for better organization
396401
categories = {
397-
"Basic Equality Matchers" => ["eq with strings", "eq with numbers", "eq with arrays", "eq with hashes", "eq with nested structures", "eq with array of symbols", "eq with nil"],
402+
"Basic Equality Matchers" => ["eq with strings", "eq with numbers", "eq with arrays", "eq with hashes", "eq with nested structures", "eq with array of symbols", "eq with nil", "eq with proc"],
398403
"Identity Matchers" => ["be (object identity)", "equal (alias for be)"],
399404
"Comparison Matchers" => ["be >", "be <", "be >=", "be <=", "be_between", "be_within"],
400405
"Type Matchers" => ["be_a / be_kind_of", "be_an_instance_of"],
@@ -403,7 +408,6 @@ def initialize
403408
"Collection Matchers" => ["include", "include with multiple items", "include with hash", "start_with", "end_with", "match (regex)", "match (regex) with custom message", "contain_exactly", "match_array", "all"],
404409
"String Matchers" => ["match with string", "unescaping quotes in actual", "strings with newlines"],
405410
"Change Matchers" => ["change", "change by", "change by_at_least", "change by_at_most"],
406-
"Output Matchers" => ["output to stdout", "output to stderr"],
407411
"Exception Matchers" => ["raise_error", "raise_error with message", "raise_error when none raised", "unexpected exception (outside expect block)"],
408412
"Other Matchers" => ["throw_symbol", "exist", "cover", "cover multiple values", "respond_to", "respond_to with arguments", "have_attributes", "satisfy", "satisfy with complex block"],
409413
"Compound & Negated" => ["and", "or", "not_to eq", "not_to include"],

lib/rspec/enriched_json/expectation_helper_wrapper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ module Serializer
4545
def serialize_value(value)
4646
if value.is_a?(Regexp)
4747
return Oj.dump(value.inspect, mode: :compat)
48+
elsif value.is_a?(Proc)
49+
return value.call
4850
end
4951

5052
Oj.dump(value, OJ_OPTIONS)

lib/rspec/enriched_json/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module RSpec
44
module EnrichedJson
5-
VERSION = "0.8.1"
5+
VERSION = "0.8.2"
66
end
77
end

spec/oj_serialization_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
end
4444
end
4545

46+
describe "serialization of Proc objects" do
47+
it "calls a simple Proc" do
48+
helloworld = proc { "Hello, world!" }
49+
result = serializer.serialize_value(helloworld)
50+
expect(result).to eq("Hello, world!")
51+
end
52+
end
53+
4654
describe "Fallback behavior for errors" do
4755
it "uses fallback format when Oj.dump fails" do
4856
# Create an object that we'll mock to fail

0 commit comments

Comments
 (0)