weewar.com corner

Viewing a page in a browser

Posted on February 27th, 2007 by Duff OMelia

I’ve been doing a bunch of integration testing of a rails site lately. I have found it quite useful to be able to quickly view the current page in a browser.

I added the following method to my integration testing DSL:

module IntegrationDsl

  def view
    filename = File.dirname(__FILE__) + "/integration/.integration_test_output_for_browser.html"
    File.open(filename, "w+") { | file | file.write(response.body) }
    `open #{filename}`
  end

end

It simply writes out the response body to a file and then opens it (using the `open` on a mac).

So now in my integration test, I can view the current page in a browser like this:

def test_feature
  s = new_session_as :duff
  s.view
end

Comments »

  1. gritmonkey said,

    March 13th, 2007 at 09:37 PM

    Just what I was looking for, thanks!

Leave a Comment