Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions demo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"],
Expand All @@ -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"],
Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/enriched_json/expectation_helper_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/enriched_json/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module RSpec
module EnrichedJson
VERSION = "0.8.1"
VERSION = "0.8.2"
end
end
8 changes: 8 additions & 0 deletions spec/oj_serialization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading