Testing binary downloads with Webrat

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.

up-down-load

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]}"
)

Comments

7 responses to “Testing binary downloads with Webrat”

  1. […] Testing binary downloads with Webrat 1 day ago […]

  2. […] Testing binary downloads with webrat – a suggestion for a possible way to test downloads. […]

  3. […] Testing binary downloads with Webrat : Witold Rugowski aka NetManiac […]

  4. […] Testing binary downloads with Webrat By Witold Rugowski of NetManiac 11 months ago. […]

  5. […] similar? > Thanks. This should be possible, perhaps by parsing response_body as suggested at https://nhw.pl/wp/2009/09/09/testing-binary-downloads-with-webrat . Best, — Marnen Laibow-Koser http://www.marnen.orgmarnen@… — Posted via […]

  6. […] similar? > Thanks. This should be possible, perhaps by parsing response_body as suggested at https://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

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.