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

7 thoughts on “Testing binary downloads with Webrat

  1. Pingback: The Ruby Toolbox: Browser testing

  2. Pingback: Emphasized Insanity: Bag O' Links - 11/9/2009

  3. Pingback: Ennuyer.net » Blog Archive » Rails Reading - Sept 10, 2009

  4. Pingback: The Ruby Reflector - Webrat

  5. Pingback: Old Nabble - RubyOnRails Users - Test files downloads with Cucumber

  6. Pingback: View topic - Test files downloads with Cucumber :: For Linux & Unix Server Administrators and Developers :: BlueQuartz.US

  7. Pingback: [Rails] Re: Test files downloads with Cucumber

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>