Module: Rspec::HtmlMessages::ValueFormatter
- Included in:
- Rspec::HtmlMessages
- Defined in:
- lib/rspec/html_messages/value_formatter.rb
Constant Summary collapse
- OJ_LOAD_OPTIONS =
Oj options for deserializing - use object mode to restore symbols but keep safety options to prevent code execution
{ mode: :object, # Restore Ruby objects and symbols auto_define: false, # DON'T auto-create classes (safety) symbol_keys: false, # Preserve symbols as they were serialized circular: true, # Handle circular references create_additions: false, # Don't allow custom deserialization (safety) create_id: nil # Disable create_id (safety) }.freeze
- AWESOME_PRINT_OPTIONS =
{ plain: true, # No color codes index: false, # No array indices indent: -2, # 2-space indentation sort_keys: true, # Consistent hash ordering object_id: false, # No object IDs raw: true # Show instance variables }
Instance Method Summary collapse
Instance Method Details
#deserialize_value(serialized_value) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/rspec/html_messages/value_formatter.rb', line 37 def deserialize_value(serialized_value) return nil unless serialized_value Oj.load(serialized_value, OJ_LOAD_OPTIONS) rescue Oj::ParseError, EncodingError, TypeError serialized_value end |
#prettify_for_diff(value) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rspec/html_messages/value_formatter.rb', line 29 def prettify_for_diff(value) case value when String then value when nil then "nil" else value.awesome_inspect(AWESOME_PRINT_OPTIONS) end end |