Sha256: 811a6ab3d6ab3a6276f134e09e5f7f7427b145c0bf33fee7f183256dcb734d94

Contents?: true

Size: 1.23 KB

Versions: 6

Compression:

Stored size: 1.23 KB

Contents

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

Version data entries

6 entries across 6 versions & 4 rubygems

Version Path
davidtrogers-webrat-0.4.4.2 spec/public/save_and_open_spec.rb
diabolo-webrat-0.4.4.1 spec/public/save_and_open_spec.rb
diabolo-webrat-0.4.4.2 spec/public/save_and_open_spec.rb
diabolo-webrat-0.4.4 spec/public/save_and_open_spec.rb
raldred-webrat-0.4.4.2 spec/public/save_and_open_spec.rb
sr-webrat-0.4.4.1 spec/public/save_and_open_spec.rb