public
Created

Place this somewhere that gets loaded when RSpec starts and your browser will automatically show the contents of the webpage when an acceptance spec fails.

  • Download Gist
spec/spec_helper.rb
Ruby
1 2
# Somewhere in the file
Capybara.auto_save_and_open_page = true if 'true' == ENV['CAPYBARA_AUTO_SAVE_AND_OPEN_PAGE']
spec/support/ext/capybara.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
module Capybara
def auto_save_and_open_page=(val)
@auto_save_and_open_page = !!val
end
 
def auto_save_and_open_page?
@auto_save_and_open_page ||= false
end
end
 
module Capybara::Node::Finders
alias :orig_find :find
 
def find(*args)
begin
orig_find *args
rescue Capybara::ElementNotFound => e
session.save_and_open_page if Capybara.auto_save_and_open_page?
raise e
end
end
end
 
module Capybara::Node::Matchers
%w[has has_no].each do |has_has_no|
alias :"orig_#{has_has_no}_selector?" :"#{has_has_no}_selector?"
 
class_eval <<-METH, __FILE__, __LINE__ + 1
def #{has_has_no}_selector?(*args)
if !(result = orig_#{has_has_no}_selector?(*args)) && Capybara.auto_save_and_open_page?
session.save_and_open_page
end
result
end
METH
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.