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 +