From 1df6aa3d5ca6dee56039a4099a4e5dcf43df5a1a Mon Sep 17 00:00:00 2001 From: Jonas Nicklas Date: Tue, 24 Jul 2012 09:02:05 +0200 Subject: [PATCH] Move save_page spec into session --- lib/capybara/spec/session/save_page_spec.rb | 46 ++++++++++++++++++ spec/save_and_open_page_spec.rb | 53 --------------------- 2 files changed, 46 insertions(+), 53 deletions(-) create mode 100644 lib/capybara/spec/session/save_page_spec.rb delete mode 100644 spec/save_and_open_page_spec.rb diff --git a/lib/capybara/spec/session/save_page_spec.rb b/lib/capybara/spec/session/save_page_spec.rb new file mode 100644 index 00000000..c9e894d3 --- /dev/null +++ b/lib/capybara/spec/session/save_page_spec.rb @@ -0,0 +1,46 @@ +Capybara::SpecHelper.spec '#save_page' do + let(:alternative_path) { File.join(Dir.pwd, "save_and_open_page_tmp") } + before do + @session.visit("/foo") + end + + after do + Capybara.save_and_open_page_path = nil + Dir.glob("capybara-*.html").each do |file| + FileUtils.rm(file) + end + FileUtils.rm_rf alternative_path + end + + it "saves the page in the root directory" do + @session.save_page + path = Dir.glob("capybara-*.html").first + File.read(path).should include("Another World") + end + + it "generates a sensible filename" do + @session.save_page + path = Dir.glob("capybara-*.html").first + filename = path.split("/").last + filename.should =~ /^capybara-\d+\.html$/ + end + + it "can store files in a specified directory" do + Capybara.save_and_open_page_path = alternative_path + @session.save_page + path = Dir.glob(alternative_path + "/capybara-*.html").first + File.read(path).should include("Another World") + end + + it "uses the given filename" do + @session.save_page("capybara-001122.html") + File.read("capybara-001122.html").should include("Another World") + end + + it "returns the filename" do + result = @session.save_page + path = Dir.glob("capybara-*.html").first + filename = path.split("/").last + result.should == filename + end +end diff --git a/spec/save_and_open_page_spec.rb b/spec/save_and_open_page_spec.rb deleted file mode 100644 index 1355eb81..00000000 --- a/spec/save_and_open_page_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'spec_helper' - -require 'capybara/util/save_and_open_page' - -describe Capybara do - describe "#save_page" do - let(:alternative_path) { File.join(Dir.pwd, "save_and_open_page_tmp") } - after do - Capybara.save_and_open_page_path = nil - Dir.glob("capybara-*.html").each do |file| - FileUtils.rm(file) - end - FileUtils.rm_rf alternative_path - end - - it "saves the page in the root directory" do - html = "

Hello world

" - Capybara.save_page(html) - path = Dir.glob("capybara-*.html").first - File.read(path).should == html - end - - it "generates a sensible filename" do - html = "

Hello world

" - Capybara.save_page(html) - path = Dir.glob("capybara-*.html").first - filename = path.split("/").last - filename.should =~ /^capybara-\d+\.html$/ - end - - it "can store files in a specified directory" do - Capybara.save_and_open_page_path = alternative_path - html = "

Hello world

" - Capybara.save_page(html) - path = Dir.glob(alternative_path + "/capybara-*.html").first - File.read(path).should == html - end - - it "uses the given filename" do - html = "

Hello world

" - Capybara.save_page(html, "capybara-001122.html") - File.read("capybara-001122.html").should == html - end - - it "returns the filename" do - html = "

Hello world

" - result = Capybara.save_page(html) - path = Dir.glob("capybara-*.html").first - filename = path.split("/").last - result.should == filename - end - end -end