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
|
|
|
|
|
|
|
RAILS_ROOT = "." unless defined?(RAILS_ROOT)
|
|
|
|
|
|
|
|
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-05 03:44:00 +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>
|
|
|
|
HTML
|
2008-05-12 04:48:01 +00:00
|
|
|
|
2008-05-05 03:44:00 +00:00
|
|
|
File.stubs(:exist?).returns(true)
|
|
|
|
Time.stubs(:now).returns(1234)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should rewrite css rules" do
|
|
|
|
file_handle = mock()
|
2008-05-12 04:48:01 +00:00
|
|
|
File.expects(:open).with(filename, 'w').yields(file_handle)
|
2008-05-05 03:44:00 +00:00
|
|
|
file_handle.expects(:write).with{|html| html =~ %r|#{RAILS_ROOT}/public/stylesheets/foo.css|s }
|
|
|
|
Webrat::Page.any_instance.stubs(:open_in_browser)
|
|
|
|
@session.save_and_open_page
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should rewrite image paths" do
|
|
|
|
file_handle = mock()
|
2008-05-12 04:48:01 +00:00
|
|
|
File.expects(:open).with(filename, 'w').yields(file_handle)
|
2008-05-05 03:44:00 +00:00
|
|
|
file_handle.expects(:write).with{|html| html =~ %r|#{RAILS_ROOT}/public/images/bar.png|s }
|
|
|
|
Webrat::Page.any_instance.stubs(:open_in_browser)
|
|
|
|
@session.save_and_open_page
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should open the temp file in a browser" do
|
|
|
|
File.stubs(:open)
|
2008-05-12 04:48:01 +00:00
|
|
|
Webrat::Page.any_instance.expects(: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
|
|
|
|
File.expand_path("./webrat-1234.html")
|
|
|
|
end
|
2008-05-05 03:44:00 +00:00
|
|
|
|
|
|
|
end
|