I'm trying to write RSpec tests for an API.
Setup: To keep things consistent, we have a formatting function that takes the response and makes a nice JSON object so everything is consistent. E.g.- simplified for this example:
def format (status, message)
{status: status,
message: message}
end
This function is declared in a base controller that all the API controllers inherit from.
What I'd like: When I test an API controller I'd like to test that the controller gives me the expected result, but I don't want to test the actual format of the JSON response. As in, I want to check that the params passed to the format function are what I expect, but I don't want to check what that function actually returns. (I'm planning on testing that function in another test. I'd really like it if a change to the JSON format didn't affect every test for the API. If this isn't good practice feel free to let me know.)
My questions: Is there any way for me to access that format function from the base controller in the current API spec file? Or is there a good way for me to stub it out and get access to the params passed to it so I can check if they're correct?