webrat/spec/api/save_and_open_spec.rb

54 lines
1.4 KiB
Ruby
Raw Normal View History

require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
describe "save_and_open_page" do
before do
@session = Webrat::TestSession.new
@session.response_body = <<-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" />
</body>
</html>
HTML
2008-07-25 23:11:56 +00:00
File.stub!(:exist?).and_return(true)
Time.stub!(:now).and_return(1234)
@session.current_page.stub!(:open_in_browser)
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|#{@session.doc_root}/stylesheets/foo.css|s
end
@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
end
@session.save_and_open_page
end
it "should open the temp file in a browser" do
2008-07-25 23:11:56 +00:00
@session.current_page.should_receive(:open_in_browser).with(filename)
@session.save_and_open_page
end
def filename
File.expand_path("./webrat-#{Time.now}.html")
end
end