webrat/spec/public/save_and_open_spec.rb

61 lines
1.5 KiB
Ruby
Raw Normal View History

require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
describe "save_and_open_page" do
before do
2008-11-23 05:22:49 +00:00
with_html <<-HTML
<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" />
<img src='/images/foo.png' />
</body>
</html>
HTML
2008-11-23 05:22:49 +00:00
File.stub!(:exist? => true)
Time.stub!(:now => 1234)
webrat_session.stub!(:open_in_browser)
2009-04-08 00:30:12 +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)
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|"#{webrat_session.doc_root}/stylesheets/foo.css"|s
end
2009-04-08 00:30:12 +00:00
2008-11-23 05:22:49 +00:00
save_and_open_page
end
2009-04-08 00:30:12 +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|
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
end
2009-04-08 00:30:12 +00:00
2008-11-23 05:22:49 +00:00
save_and_open_page
end
2009-04-08 00:30:12 +00:00
it "should open the temp file in a browser" do
2008-11-23 05:22:49 +00:00
webrat_session.should_receive(:open_in_browser).with(filename)
save_and_open_page
end
2009-04-08 00:30:12 +00:00
def filename
File.expand_path("./webrat-#{Time.now}.html")
end
end