Made aliasing conditional on Capybara version.

Actually referred to the method alias rather then the method.
This commit is contained in:
Dylan Lacey 2013-03-08 11:45:18 -08:00
parent 6ece0c1fee
commit 480d8530f9
3 changed files with 35 additions and 10 deletions

View File

@ -3,7 +3,7 @@ source :gemcutter
gemspec
gem 'rake'
gem 'capybara', "~> 1.0.0"
gem 'capybara', "~> 2.0.0"
group :test do
gem 'cucumber'

View File

@ -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

View File

@ -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