I am currently writing rspec tests in which I need to use some 'real world' data stored in objects.
To use these objects in an rspec test I used Marshal.dump(array_of_objects)
and loaded them into the spec with Marshal.load(File.read("spec/fixtures/file_name_here"))
.
Unfortunately, I keep running into an error that I don't understand how to fix (despite reading many people having the same issue):
*** TypeError Exception: incompatible marshal file format (can't be read)
format version 4.8 required; 34.92 given
Is there a way to fix this so I can run the test?
Although I haven't solved the initial issue I thought I might share how I got around it.
Instead I dumped the array of objects to a file using YAML:
File.open(file_name, 'w') { |file| file.write(YAML.dump(array_of_objects)) }
Then I loaded that file with YAML:
YAML.load(File.read("file_location"))
It seems like this is a better option than using Marshal because there are no version issues as mentioned in the question above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With