Fix saving feature failures to tmp/capybara

This commit is contained in:
Henne Vogelsang 2016-05-02 12:05:58 +02:00
parent 5e656e7d9f
commit dd5796bd34

View file

@ -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