Testing binary downloads with Webrat
Posted on September 9, 2009 - Filed Under RubyOnRails, tips
If you're new here, you may want to subscribe to my RSS feed. You can also get updates by email Thanks for visiting!
I’m using Webrat to keep some sanity when approaching maintenance of new application. Customers often come to me with legacy code, which somehow is not covered by tests.
In such case integration tests are way to go, since they provide most bang of Yours bucks – each written test could cover many parts of application.
I had to create test for testing download some data in CSV format (have You said binary? :) ). With default matchers from Webrat You won’t be able to write effective assertions – and that why I’m referring to such file as binary.

So how to do it? Here is a quick tip
Use Webrat’s response_body to get raw body returned by application. Like that:
click_link "Get me some CSV data"
ret = CSV.parse response_body
assert_equal(
2,
ret[2][5].to_f,
"In third row and sixth column You should have 2 and there is #{ret[2][5]}"
)
Popularity: 14% [?]
Hits for this post: 6773
Similar Posts
- Testing Rails application with ActsAsAuthenticated plugin
- Shoulda You abandon Test::Unit?
- Using non text values as arguments in functional tests
- Did I just cross Rubicon?
- D-Link and PHK have settled
Comments
7 Responses to “Testing binary downloads with Webrat”
-
The Ruby Toolbox: Browser testing on
September 10th, 2009 10:07
[...] Testing binary downloads with Webrat 1 day ago [...]
-
Emphasized Insanity: Bag O' Links - 11/9/2009 on
September 11th, 2009 18:34
[...] Testing binary downloads with webrat – a suggestion for a possible way to test downloads. [...]
-
Ennuyer.net » Blog Archive » Rails Reading - Sept 10, 2009 on
October 29th, 2009 12:24
[...] Testing binary downloads with Webrat : Witold Rugowski aka NetManiac [...]
-
The Ruby Reflector - Webrat on
July 27th, 2010 2:27
[...] Testing binary downloads with Webrat By Witold Rugowski of NetManiac 11 months ago. [...]
-
Old Nabble - RubyOnRails Users - Test files downloads with Cucumber on
November 29th, 2010 19:44
[...] similar? > Thanks. This should be possible, perhaps by parsing response_body as suggested at http://nhw.pl/wp/2009/09/09/testing-binary-downloads-with-webrat . Best, — Marnen Laibow-Koser http://www.marnen.orgmarnen@… — Posted via [...]
-
View topic - Test files downloads with Cucumber :: For Linux & Unix Server Administrators and Developers :: BlueQuartz.US on
February 3rd, 2011 3:23
[...] similar? Thanks. This should be possible, perhaps by parsing response_body as suggested at http://nhw.pl/wp/2009/09/09/testing-binary-downloads-with-webrat . Best, — Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org — Posted via [...]
-
[Rails] Re: Test files downloads with Cucumber on
April 18th, 2011 11:25
[...] similar? > Thanks. This should be possible, perhaps by parsing response_body as suggested at http://nhw.pl/wp/2009/09/09/testing-binary-downloads-with-webrat . Best, — Marnen Laibow-Koser http://www.marnen.org mar…@marnen.org — Posted via [...]
Leave a Reply


