Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec: How to fix marshal format version 4.8 required; 34.92 given error

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?

like image 975
Matt Hough Avatar asked Nov 07 '22 11:11

Matt Hough


1 Answers

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.

like image 196
Matt Hough Avatar answered Nov 12 '22 16:11

Matt Hough