CopyAndPaste

random programming notes

Test Fixtures Tricks

Often we have model classes using serialized data fields. This is how I write the YML fixture test data:

Test fixture YML example for serialized array, serialized hash, and datetime
1
2
3
4
5
one:
  id: 100
  some_hash_serialized: <%= { :profile_image_url => 'http://....png' }.to_yaml.inspect %>
  some_array_serialized: <%= [ 'hello', 'world' ].to_yaml.inspect %>
  some_datetime: <%= first_occurred_at: <%= 10.days.ago.to_s(:db) %>