I have the following method which is going to execute a lot of raw sql and return it in an array.
I then transform the array to JSON. I want to write a test that checks that this transformation to Json is correct.
def get_data
results = connection.raw_connection.execute(sql).each
transform_results(results)
end
private
def transform_results(results)
{
some_value: results[0]['some_value'],
another_value: results[0]['another_value']
}
end
How can I write some Rspec which tests the transform_results
method to check the Json is mapped correctly, assuming I mock a results
array.
Something like this?
allow_any_instance_of(?????).to receive(:each).and_return(result)