mercredi 19 juin 2019

Testing with fake model data in Ruby on Rails

Let's say I have a simple function on a class that takes a model object, transforms the data, and then returns a hash. Something like:

def model_to_hash(some_model)
  # transform model data into new hash structure
  # return the new hash
end

I want to test that data with sample data from the model in question. What is a good strategy for doing this?

Of course, one could create some mock data in the test file, but that test data could go out of sync with the actual model.

Is there a way to do this that is more directly linked to the the model using something like rspec?

Aucun commentaire:

Enregistrer un commentaire