Created
February 16, 2012 21:18
-
-
Save hoverlover/1847930 to your computer and use it in GitHub Desktop.
Auto save_and_open_page on failure for Capybara
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Capybara | |
def Capybara.auto_save_and_open_page=(val) | |
@auto_save_and_open_page = !!val | |
end | |
def Capybara.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Capybara.auto_save_and_open_page = true if 'true' == ENV['CAPYBARA_AUTO_SAVE_AND_OPEN_PAGE'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another approach: https://gist.github.com/eloyesp/f22306cbc017820e9ba86448299dac2a