2008-05-12 04:48:01 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2008-05-05 03:44:00 +00:00
|
|
|
|
|
|
|
describe "save_and_open_page" do
|
|
|
|
before do
|
2008-05-12 04:48:01 +00:00
|
|
|
@session = Webrat::TestSession.new
|
|
|
|
|
|
|
|
@session.response_body = <<-HTML
|
2008-05-12 04:58:24 +00:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<link href="/stylesheets/foo.css" media="screen" rel="stylesheet" type="text/css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>Hello world</h1>
|
|
|
|
<img src="/images/bar.png" />
|
|
|
|
</body>
|
|
|
|
</html>
|
2008-05-05 03:44:00 +00:00
|
|
|
HTML
|
2008-05-12 04:48:01 +00:00
|
|
|
|
2008-07-25 23:11:56 +00:00
|
|
|
File.stub!(:exist?).and_return(true)
|
|
|
|
Time.stub!(:now).and_return(1234)
|
2008-07-27 16:41:52 +00:00
|
|
|
@session.stub!(:open_in_browser)
|
2008-05-12 04:58:24 +00:00
|
|
|
|
2008-07-25 23:11:56 +00:00
|
|
|
@file_handle = mock("file handle")
|
|
|
|
File.stub!(:open).with(filename, 'w').and_yield(@file_handle)
|
|
|
|
@file_handle.stub!(:write)
|
2008-05-05 03:44:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should rewrite css rules" do
|
2008-07-25 23:11:56 +00:00
|
|
|
@file_handle.should_receive(:write) do |html|
|
|
|
|
html.should =~ %r|#{@session.doc_root}/stylesheets/foo.css|s
|
2008-05-12 04:58:24 +00:00
|
|
|
end
|
|
|
|
|
2008-05-05 03:44:00 +00:00
|
|
|
@session.save_and_open_page
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should rewrite image paths" do
|
2008-07-25 23:11:56 +00:00
|
|
|
@file_handle.should_receive(:write) do |html|
|
|
|
|
html.should =~ %r|#{@session.doc_root}/images/bar.png|s
|
2008-05-12 04:58:24 +00:00
|
|
|
end
|
|
|
|
|
2008-05-05 03:44:00 +00:00
|
|
|
@session.save_and_open_page
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should open the temp file in a browser" do
|
2008-07-27 16:41:52 +00:00
|
|
|
@session.should_receive(:open_in_browser).with(filename)
|
2008-05-05 03:44:00 +00:00
|
|
|
@session.save_and_open_page
|
|
|
|
end
|
2008-05-12 04:48:01 +00:00
|
|
|
|
|
|
|
def filename
|
2008-05-12 04:58:24 +00:00
|
|
|
File.expand_path("./webrat-#{Time.now}.html")
|
2008-05-12 04:48:01 +00:00
|
|
|
end
|
2008-05-05 03:44:00 +00:00
|
|
|
|
|
|
|
end
|