@@ -98,6 +98,11 @@ RSpec.configure do |config|
9898 # Set this value to put all snapshots in a fixed directory
9999 config.snapshot_dir = " spec/fixtures/snapshots"
100100
101+ # Defaults to not applying any additional formatting
102+ #
103+ # Set this value to use a custom formatter for when `expect` receives a string
104+ config.snapshot_formatter = MyFavoriteFormatter
105+
101106 # Defaults to using the awesome_print gem to serialize values for snapshots
102107 #
103108 # Set this value to use a custom snapshot serializer
@@ -114,18 +119,31 @@ You can pass custom serializers to `rspec-snapshot` if you prefer. Pass a serial
114119matcher as a config option:
115120
116121``` ruby
122+ # Set a custom string formatter for all tests
123+ RSpec .configure do |config |
124+ config.snapshot_formatter = MyCoolGeneralFormatter
125+ end
126+
117127# Set a custom serializer for all tests
118128RSpec .configure do |config |
119129 config.snapshot_serializer = MyCoolGeneralSerializer
120130end
121131
122- # Set a custom serializer for this specific test
132+ # Set a custom formatter for this specific test
123133expect(html_response).to(
124- match_snapshot(' html_response' , { snapshot_serializer: MyAwesomeHTMLSerializer })
134+ match_snapshot(' html_response' , { snapshot_formatter: MyAwesomeFormatter })
135+ )
136+
137+ # Set a custom serializer for this specific test
138+ expect(result_object).to(
139+ match_snapshot(' result_object' , { snapshot_serializer: MyAwesomeSerializer })
125140)
126141```
127142
128- Serializer classes are required to have one instance method ` dump ` which takes
143+ Formatters are required to have a single ` call ` method that takes the raw string value
144+ and returns a formatted string. If you want, you can use a proc or lambda.
145+
146+ Serializer classes are required to have one instance method ` dump ` , which takes
129147the value to be serialized and returns a string.
130148
131149## Migration
0 commit comments