mattheworiordan / capybara-screenshot

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

in rspec, only test Capybara.page.current_url when there is an expectation exception #197

Closed yanowitz closed 7 years ago

yanowitz commented 7 years ago

The previous logic meant every test (even ones that didn't use Capybara) caused Firefox to open after every test, even when there wasn't a test failure.

There's probably a better way to do this (Capybara::DSL ends up in all our rspec groups) based on whether it was an integration test or made use of Capybara, but this at least solves a chunk of the annoyance.

yanowitz commented 7 years ago

@mattheworiordan was this a terrible idea or are you just terribly busy?

mattheworiordan commented 7 years ago

@yanowitz I apologize. I am just terribly busy and neglected this gem.

Thanks for your contribution, however I am confused, how is:

if Capybara.page.current_url != '' && Capybara::Screenshot.autosave_on_failure && example.exception

any different logically to?

if Capybara::Screenshot.autosave_on_failure && example.exception && Capybara.page.current_url != ''
yanowitz commented 7 years ago

Fair question.

Capybara.page.current_url has a side-effect: it launches (opens) a browser if one is not already launched. So by putting it after the other two pieces of the conditional, we short circuit if there has been no exception and do not launch the browser.

mattheworiordan commented 7 years ago

has a side-effect: it launches (opens) a browser if one is not already launched

Ah, thanks for explaining.

mattheworiordan commented 7 years ago

Thanks for the contribution!