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