mattheworiordan / capybara-screenshot

Automatically save screen shots when a Capybara scenario fails
MIT License
1.02k stars 168 forks source link

Clean up subdirectories when pruning #222

Closed timrogers closed 6 years ago

timrogers commented 7 years ago

The pruning functionality included in this gem makes it easy to clean up old screenshots.

By configuring Capybara::Screenshot.register_filename_prefix_formatter, you can set your own path for screenshots to be captured at, which may include a more complicated directory structure (for example, for one of my projects, we want to organise screenshots based on the spec file that generated them, with the filename including the line number of the example).

At the moment, Pruner only cleans up *.{html,png}, meaning that more complex directory structures are not pruned. This switches to using the glob **/*.{html,png}, delving into subdirectories, and then deleting any empty subdirectories at the end.

mattheworiordan commented 7 years ago

Thanks for this @timrogers.

I like this change, but am a little worried about the implications of this. It seems a bit dangerous that we would delete files in folders that we have no idea are related to the gem itself. Would it not be better to allow a custom path to be provided, or perhaps a flag to enable directory recursive wildcard pruning?

timrogers commented 7 years ago

Hmm, you're right. I'm making the assumption here that you only store screenshots within the directory structure, but it's correct that you might store other things too. I'll look at making recursive pruning optional.

timrogers commented 7 years ago

Are the failures anything to do with me by the way? It looks like the message raised by Capybara has changed to mention a "visible link or button".

timrogers commented 6 years ago

I'm not going to have time to work further on this realistically, and I think there are challenges to doing this well, so I'm going to close the PR.