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-11-23 05:22:49 +00:00
|
|
|
with_html <<-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" />
|
2009-05-08 11:01:46 +00:00
|
|
|
<img src='/images/foo.png' />
|
2008-05-12 04:58:24 +00:00
|
|
|
</body>
|
|
|
|
</html>
|
2008-05-05 03:44:00 +00:00
|
|
|
HTML
|
2008-05-12 04:48:01 +00:00
|
|
|
|
2008-11-23 05:22:49 +00:00
|
|
|
File.stub!(:exist? => true)
|
|
|
|
Time.stub!(:now => 1234)
|
2009-06-15 01:38:04 +00:00
|
|
|
|
|
|
|
require "launchy"
|
|
|
|
Launchy::Browser.stub!(:run)
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-07-25 23:11:56 +00:00
|
|
|
@file_handle = mock("file handle")
|
2010-01-17 00:18:28 +00:00
|
|
|
File.stub!(:open).and_yield(@file_handle)
|
2008-07-25 23:11:56 +00:00
|
|
|
@file_handle.stub!(:write)
|
2008-05-05 03:44:00 +00:00
|
|
|
end
|
|
|
|
|
2010-01-17 00:18:28 +00:00
|
|
|
it "should save pages to the directory configured" do
|
|
|
|
Webrat.configuration.stub!(:saved_pages_dir => "path/to/dir")
|
|
|
|
File.should_receive(:open).with("path/to/dir/webrat-1234.html", "w").and_yield(@file_handle)
|
|
|
|
|
|
|
|
save_and_open_page
|
|
|
|
end
|
|
|
|
|
2008-05-05 03:44:00 +00:00
|
|
|
it "should rewrite css rules" do
|
2008-07-25 23:11:56 +00:00
|
|
|
@file_handle.should_receive(:write) do |html|
|
2009-05-08 11:01:46 +00:00
|
|
|
html.should =~ %r|"#{webrat_session.doc_root}/stylesheets/foo.css"|s
|
2008-05-12 04:58:24 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-11-23 05:22:49 +00:00
|
|
|
save_and_open_page
|
2008-05-05 03:44:00 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2009-05-08 11:01:46 +00:00
|
|
|
it "should rewrite image paths with double quotes" do
|
2008-07-25 23:11:56 +00:00
|
|
|
@file_handle.should_receive(:write) do |html|
|
2009-05-08 11:01:46 +00:00
|
|
|
html.should =~ %r|"#{webrat_session.doc_root}/images/bar.png"|s
|
|
|
|
end
|
|
|
|
|
|
|
|
save_and_open_page
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should rewrite image paths with single quotes" do
|
|
|
|
@file_handle.should_receive(:write) do |html|
|
|
|
|
html.should =~ %r|'#{webrat_session.doc_root}/images/foo.png'|s
|
2008-05-12 04:58:24 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-11-23 05:22:49 +00:00
|
|
|
save_and_open_page
|
2008-05-05 03:44:00 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2009-06-15 01:38:04 +00:00
|
|
|
it "should open the temp file in a browser with Launchy" do
|
|
|
|
Launchy::Browser.should_receive(:run)
|
2008-11-23 05:22:49 +00:00
|
|
|
save_and_open_page
|
2008-05-05 03:44:00 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2009-06-15 01:38:04 +00:00
|
|
|
it "should fail gracefully if Launchy is not available" do
|
|
|
|
Launchy::Browser.should_receive(:run).and_raise(LoadError)
|
|
|
|
|
|
|
|
lambda do
|
|
|
|
save_and_open_page
|
|
|
|
end.should_not raise_error
|
|
|
|
end
|
|
|
|
|
2008-05-05 03:44:00 +00:00
|
|
|
end
|