46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/rspec/enriched_json/expectation_helper_wrapper.rb', line 46
def serialize_value(value)
if value.is_a?(Regexp)
return Oj.dump(value.inspect, mode: :compat)
elsif value.is_a?(Proc)
original_stdout = $stdout
$stdout = StringIO.new
value.call
output = $stdout.string
$stdout = original_stdout
return output
end
Oj.dump(value, OJ_OPTIONS)
rescue => e
Oj.dump({
"_serialization_error" => e.message,
"_class" => value.class.name,
"_to_s" => begin
value.to_s
rescue
"[to_s failed]"
end
}, mode: :compat)
end
|