1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Move save_page spec into session

This commit is contained in:
Jonas Nicklas 2012-07-24 09:02:05 +02:00
parent 54dbf744d4
commit 1df6aa3d5c
2 changed files with 46 additions and 53 deletions

View file

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

View file

@ -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 = "<h1>Hello world</h1>"
Capybara.save_page(html)
path = Dir.glob("capybara-*.html").first
File.read(path).should == html
end
it "generates a sensible filename" do
html = "<h1>Hello world</h1>"
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 = "<h1>Hello world</h1>"
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 = "<h1>Hello world</h1>"
Capybara.save_page(html, "capybara-001122.html")
File.read("capybara-001122.html").should == html
end
it "returns the filename" do
html = "<h1>Hello world</h1>"
result = Capybara.save_page(html)
path = Dir.glob("capybara-*.html").first
filename = path.split("/").last
result.should == filename
end
end
end