Skip to content
Browse files

Capybara 2 support

  • Loading branch information...
1 parent f5f2f58 commit 651d9278e1a6f757a3a8e66a48774874eedcdb3b @mattheworiordan committed Nov 26, 2012
Showing with 16 additions and 9 deletions.
  1. +1 −1 capybara-screenshot.gemspec
  2. +8 −6 lib/capybara-screenshot/rspec.rb
  3. +7 −2 lib/capybara-screenshot/saver.rb
View
2 capybara-screenshot.gemspec
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
s.rubyforge_project = "capybara-screenshot"
- s.add_dependency 'capybara', '>= 1.0'
+ s.add_dependency 'capybara', ['>= 1.0', '< 3']
s.add_development_dependency 'rspec', '~> 2.7'
s.add_development_dependency 'timecop'
View
14 lib/capybara-screenshot/rspec.rb
@@ -1,13 +1,15 @@
RSpec.configure do |config|
# use the before hook to add an after hook that runs last
- config.after(:type => :request) do
- if Capybara::Screenshot.autosave_on_failure && example.exception
- filename_prefix = Capybara::Screenshot.filename_prefix_for(:rspec, example)
+ config.after do
+ if Capybara.page.respond_to?(:save_page) # Capybara DSL method has been included for a feature we can snapshot
+ if Capybara::Screenshot.autosave_on_failure && example.exception
+ filename_prefix = Capybara::Screenshot.filename_prefix_for(:rspec, example)
- saver = Capybara::Screenshot::Saver.new(Capybara, Capybara.page, true, filename_prefix)
- saver.save
+ saver = Capybara::Screenshot::Saver.new(Capybara, Capybara.page, true, filename_prefix)
+ saver.save
- example.metadata[:full_description] += "\n Screenshot: #{saver.screenshot_path}"
+ example.metadata[:full_description] += "\n Screenshot: #{saver.screenshot_path}"
+ end
end
end
end
View
9 lib/capybara-screenshot/saver.rb
@@ -17,8 +17,13 @@ def save
end
def save_html
- require 'capybara/util/save_and_open_page'
- capybara.save_page(page.body, "#{file_base_name}.html")
+ if Capybara::VERSION.match(/^\d+/)[0] == '1'
+ require 'capybara/util/save_and_open_page'
+ capybara.save_page(page.body, "#{file_base_name}.html")
+ else
+ capybara.save_page("#{file_base_name}.html")
+ end
+ warn "Saved file #{file_base_name}"
end
def save_screenshot

0 comments on commit 651d927

Please sign in to comment.
Something went wrong with that request. Please try again.