From 480d8530f9d9e8497110ad0d688724365415d388 Mon Sep 17 00:00:00 2001 From: Dylan Lacey Date: Fri, 8 Mar 2013 11:45:18 -0800 Subject: [PATCH] Made aliasing conditional on Capybara version. Actually referred to the method alias rather then the method. --- Gemfile | 2 +- lib/sauce/capybara.rb | 21 ++++++++++++++++----- spec/sauce/capybara_spec.rb | 22 ++++++++++++++++++---- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index 7b50957..c1d4839 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source :gemcutter gemspec gem 'rake' -gem 'capybara', "~> 1.0.0" +gem 'capybara', "~> 2.0.0" group :test do gem 'cucumber' diff --git a/lib/sauce/capybara.rb b/lib/sauce/capybara.rb index 56d144b..f467ad6 100644 --- a/lib/sauce/capybara.rb +++ b/lib/sauce/capybara.rb @@ -60,14 +60,25 @@ module Sauce alias :base_within_frame :within_frame alias :base_within_window :within_window alias :base_find_window :find_window - #alias :base_body :body - #alias :base_source :source alias :base_execute_script :execute_script alias :base_evaluate_script :evaluate_script - [:find, :visit, :current_url, :reset!, :within_frame, - :within_window, :find_window, :source, - :execute_script, :evaluate_script].each do |method| + @methods_to_retry = [ :find, :visit, :current_url, :reset!, + :within_frame, :within_window, :find_window, :source, + :execute_script, :evaluate_script + ] + + if Gem::Version.new(::Capybara::VERSION) < Gem::Version.new(2) + alias :base_body :body + alias :base_source :source + + @methods_to_retry + [:body, :source] + else + alias :base_html :html + @methods_to_retry + [:html] + end + + @methods_to_retry.each do |method| define_method(method) do |*args, &block| handle_retry(method, *args, &block) end diff --git a/spec/sauce/capybara_spec.rb b/spec/sauce/capybara_spec.rb index 19b1c95..4b8a138 100644 --- a/spec/sauce/capybara_spec.rb +++ b/spec/sauce/capybara_spec.rb @@ -45,13 +45,13 @@ describe Sauce::Capybara do describe "#body" do context "With Capybara 1.x", :capybara_version => 1 do it "should not exist in version 2" do - driver.should respond_to :body + driver.should respond_to :base_body end end context "With Capybara 2.x", :capybara_version => 2 do it "should not exist" do - driver.should_not respond_to :body + driver.should_not respond_to :base_body end end end @@ -59,13 +59,27 @@ describe Sauce::Capybara do describe "#source" do context "With Capybara 1", :capybara_version => 1 do it "should exist" do - driver.should respond_to :source + driver.should respond_to :base_source end end context "with Capybara 2.x", :capybara_version => 2 do it "should not exist" do - driver.should_not respond_to :source + driver.should_not respond_to :base_source + end + end + end + + describe "#html" do + context "With Capybara 1.x", :capybara_version => 1 do + it "should not exist" do + driver.should_not respond_to :base_html + end + end + + context "With Capybara 2.x", :capybara_version => 2 do + it "should exist" do + driver.should respond_to :base_html end end end