Viewing a page in a browser

posted: February 27th, 2007

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:

1 module IntegrationDsl
2   
3   def view
4     filename = File.dirname(__FILE__) + "/integration/.integration_test_output_for_browser.html"
5     File.open(filename, "w+") { | file | file.write(response.body) }
6     `open #{filename}`
7   end
8 
9 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:

1 def test_feature
2   s = new_session_as :duff
3   s.view
4 end