public
Description: Webrat - Ruby Acceptance Testing for Web applications
Homepage: http://gitrdoc.com/brynary/webrat/tree/master/
Clone URL: git://github.com/brynary/webrat.git
webrat / spec / public / save_and_open_spec.rb
100644 52 lines (41 sloc) 1.281 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
 
describe "save_and_open_page" do
  before do
    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" />
</body>
</html>
HTML
 
    File.stub!(:exist? => true)
    Time.stub!(:now => 1234)
    webrat_session.stub!(:open_in_browser)
    
    @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
    @file_handle.should_receive(:write) do |html|
      html.should =~ %r|#{webrat_session.doc_root}/stylesheets/foo.css|s
end
save_and_open_page
end
it "should rewrite image paths" do
@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 open the temp file in a browser" do
    webrat_session.should_receive(:open_in_browser).with(filename)
    save_and_open_page
  end
  
  def filename
    File.expand_path("./webrat-#{Time.now}.html")
  end
 
end