From dd5796bd34ac4e47b3d601678e16486d640490b8 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Mon, 2 May 2016 12:05:58 +0200 Subject: [PATCH] Fix saving feature failures to tmp/capybara --- spec/support/save_feature_failures.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/spec/support/save_feature_failures.rb b/spec/support/save_feature_failures.rb index 4cfb68d4..3109c993 100644 --- a/spec/support/save_feature_failures.rb +++ b/spec/support/save_feature_failures.rb @@ -1,18 +1,20 @@ -# Automatically save and open the page -# whenever an expectation is not met in a features spec +# Automatically save the page a test fails +Capybara.save_and_open_page_path = Rails.root.join('tmp', 'capybara') + RSpec.configure do |config| config.after(:each, type: :feature) do - ename = RSpec.current_example.full_description - ename = ename.gsub ' ', '_' - ename.downcase! - ename = ename + '.html' + example_filename = RSpec.current_example.full_description + example_filename = example_filename.tr(' ', '_') + example_filename = example_filename + '.html' + example_filename = File.expand_path(example_filename, Capybara.save_and_open_page_path) if RSpec.current_example.exception.present? - save_page(ename) + save_page(example_filename) else - capfile = File.expand_path(ename, Capybara.save_and_open_page_path) - if File.exist?(capfile) - File.unlink(capfile) + # remove the file if the test starts working again + if File.exist?(example_filename) + File.unlink(example_filename) end end end end +