diff --git a/demo.rb b/demo.rb index a534661..4365d25 100755 --- a/demo.rb +++ b/demo.rb @@ -60,6 +60,11 @@ it "eq with nil" do expect("Alice").to eq(nil) end + + it "eq with proc" do + helloworld = proc { "Hello, world!" } + expect(helloworld).to eq("Hello!") + end # Identity Matchers it "be (object identity)" do @@ -394,7 +399,7 @@ def initialize # Group examples by category for better organization categories = { - "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"], + "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"], "Identity Matchers" => ["be (object identity)", "equal (alias for be)"], "Comparison Matchers" => ["be >", "be <", "be >=", "be <=", "be_between", "be_within"], "Type Matchers" => ["be_a / be_kind_of", "be_an_instance_of"], @@ -403,7 +408,6 @@ def initialize "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"], "String Matchers" => ["match with string", "unescaping quotes in actual", "strings with newlines"], "Change Matchers" => ["change", "change by", "change by_at_least", "change by_at_most"], - "Output Matchers" => ["output to stdout", "output to stderr"], "Exception Matchers" => ["raise_error", "raise_error with message", "raise_error when none raised", "unexpected exception (outside expect block)"], "Other Matchers" => ["throw_symbol", "exist", "cover", "cover multiple values", "respond_to", "respond_to with arguments", "have_attributes", "satisfy", "satisfy with complex block"], "Compound & Negated" => ["and", "or", "not_to eq", "not_to include"], diff --git a/lib/rspec/enriched_json/expectation_helper_wrapper.rb b/lib/rspec/enriched_json/expectation_helper_wrapper.rb index 6a9768b..005483d 100644 --- a/lib/rspec/enriched_json/expectation_helper_wrapper.rb +++ b/lib/rspec/enriched_json/expectation_helper_wrapper.rb @@ -45,6 +45,8 @@ module Serializer def serialize_value(value) if value.is_a?(Regexp) return Oj.dump(value.inspect, mode: :compat) + elsif value.is_a?(Proc) + return value.call end Oj.dump(value, OJ_OPTIONS) diff --git a/lib/rspec/enriched_json/version.rb b/lib/rspec/enriched_json/version.rb index 6e7f6d9..6d88539 100644 --- a/lib/rspec/enriched_json/version.rb +++ b/lib/rspec/enriched_json/version.rb @@ -2,6 +2,6 @@ module RSpec module EnrichedJson - VERSION = "0.8.1" + VERSION = "0.8.2" end end diff --git a/spec/oj_serialization_spec.rb b/spec/oj_serialization_spec.rb index 0fe9030..0bb7b7c 100644 --- a/spec/oj_serialization_spec.rb +++ b/spec/oj_serialization_spec.rb @@ -43,6 +43,14 @@ end end + describe "serialization of Proc objects" do + it "calls a simple Proc" do + helloworld = proc { "Hello, world!" } + result = serializer.serialize_value(helloworld) + expect(result).to eq("Hello, world!") + end + end + describe "Fallback behavior for errors" do it "uses fallback format when Oj.dump fails" do # Create an object that we'll mock to fail