Fix saving feature failures to tmp/capybara
This commit is contained in:
parent
5e656e7d9f
commit
dd5796bd34
1 changed files with 12 additions and 10 deletions
|
|
@ -1,18 +1,20 @@
|
||||||
# Automatically save and open the page
|
# Automatically save the page a test fails
|
||||||
# whenever an expectation is not met in a features spec
|
Capybara.save_and_open_page_path = Rails.root.join('tmp', 'capybara')
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.after(:each, type: :feature) do
|
config.after(:each, type: :feature) do
|
||||||
ename = RSpec.current_example.full_description
|
example_filename = RSpec.current_example.full_description
|
||||||
ename = ename.gsub ' ', '_'
|
example_filename = example_filename.tr(' ', '_')
|
||||||
ename.downcase!
|
example_filename = example_filename + '.html'
|
||||||
ename = ename + '.html'
|
example_filename = File.expand_path(example_filename, Capybara.save_and_open_page_path)
|
||||||
if RSpec.current_example.exception.present?
|
if RSpec.current_example.exception.present?
|
||||||
save_page(ename)
|
save_page(example_filename)
|
||||||
else
|
else
|
||||||
capfile = File.expand_path(ename, Capybara.save_and_open_page_path)
|
# remove the file if the test starts working again
|
||||||
if File.exist?(capfile)
|
if File.exist?(example_filename)
|
||||||
File.unlink(capfile)
|
File.unlink(example_filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue