From fa798ae3d521ea2c221fb4746426afd6b142e559 Mon Sep 17 00:00:00 2001 From: Jonas Nicklas Date: Mon, 26 Aug 2013 14:54:30 +0200 Subject: [PATCH] Always return an absolute path from save_page, closes #1144 --- lib/capybara/session.rb | 2 +- lib/capybara/spec/session/save_page_spec.rb | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/capybara/session.rb b/lib/capybara/session.rb index c846f9fb..ad4a25a5 100644 --- a/lib/capybara/session.rb +++ b/lib/capybara/session.rb @@ -320,7 +320,7 @@ module Capybara # def save_page(path=nil) path ||= "capybara-#{Time.new.strftime("%Y%m%d%H%M%S")}#{rand(10**10)}.html" - path = File.expand_path(path, Capybara.save_and_open_page_path) if Capybara.save_and_open_page_path + path = File.expand_path(path, Capybara.save_and_open_page_path) FileUtils.mkdir_p(File.dirname(path)) diff --git a/lib/capybara/spec/session/save_page_spec.rb b/lib/capybara/spec/session/save_page_spec.rb index 2ee2544d..a68984bb 100644 --- a/lib/capybara/spec/session/save_page_spec.rb +++ b/lib/capybara/spec/session/save_page_spec.rb @@ -37,11 +37,17 @@ Capybara::SpecHelper.spec '#save_page' do File.read("capybara-001122.html").should include("Another World") end - it "returns the filename" do + it "returns an absolute path in pwd" do result = @session.save_page - path = Dir.glob("capybara-*.html").first - filename = path.split("/").last - result.should == filename + path = File.expand_path(Dir.glob("capybara-*.html").first, Dir.pwd) + result.should == path + end + + it "returns an absolute path in given directory" do + Capybara.save_and_open_page_path = alternative_path + result = @session.save_page + path = File.expand_path(Dir.glob(alternative_path + "/capybara-*.html").first, alternative_path) + result.should == path end context "asset_host contains a string" do