I don't think printing is something that the backend should be concerned with, or even the rendering engine of the browser for that matter. It is simply something that is supported by a browser either through a custom function (like Chrome) or the default operating system printing panel (like Safari).
This brings me to the next question. What is it that you want to test? You want to test if printing works? That seems like a bit out-of-scope for your RSpec tests. You already say you test the function that creates a PDF for the user which is then downloaded. From that moment on, whatever happens to that PDF is outside of the scope of your application, so it is not testable and most certainly should not be tested.
As long as the PDF function works, you know your application works. From personal experience, what happens next is completely a black box, with some people not understanding what a PDF is and others not knowing how to control their printer. So instead of focusing on this test, I would focus on writing some documentation that goes along with your PDF download.
update
Here's what you can do if you use the Window.print()
function:
Window.print()
does not return any value for you to check, but you could wrap that function inside your own function and add your own return value.
Of course, that would only test that the wrapper function is actually called, but not if the print() function fired correctly. But rest assured, there are far bigger companies making sure that their print functionality works in their browsers, so the same way that you shouldn't test basic Rails methods like validations
, you should also skip testing browser things like print()
and back()
.
The only thing you can check is that you offer a solution when the user has javascript disabled.