We need more to be shown in the reports?!

What about all the files created during the spec? It would be great if all the pdf, image and whatever files saved or generated during the specs are accessible directly from the report. With the current formatter, only screenshot and html of the page are saved. But it’s relatively easy to add this functionality to the formatter - we just have to keep track of all the file names, which are used during the spec and use it in the extra_failure_content method.

Keeping track of the used filenames is going to be a task for the file_path method which is currently implemented like this:

If you remember then this method is currently used by save_screenshot and save_html methods to generate unique filenames. We should change this method to remember all the filenames generated and when spec fails, then just add all the links to the output. For it to work properly then all the specs should just use this method when dealing with files and everything else will be taken care by the formatter itself. After a little modification the method looks like this:

As you can see there’s only one line added which adds the generated filename to the @files_saved_during_example array. I’ve also added a possibility to add description to each file for even more readable reports.

Next problem is how to access this file_path method from our specs? Again, for simpilicity’s sake i’m going to use global variable which will be removed together with $browser variable in some of the next post’s. Let’s just create this global variable in formatter’s initialize method and then use it in the spec like this:

In short summary this spec just creates 2 simple text files where one also uses file_path description parameter. These files doesn’t have to be created by the spec itself but you could also save some files from the browser by using formatter’s file_path method when setting file save as path. Although few additional methods have to be created for this functionality to be used in IE since it doesn’t allow file paths to include forward slashes (/) instead of backward slashes (\). The filename should also be in absolute path instead of relative one. So, let’s create the methods native_file_path and absolute_file_path:

And let’s save one file with the browser:

The final report is located here. Try to see the differences between the previous one in functionality. The formatter code itself is of course located on GitHub.