NetManiac

Witold Rugowski on web20 wave with Ruby on Rails

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.

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

Popularity: 15% [?]

Hits for this post: 7781

Similar Posts

Comments

7 Responses to “Testing binary downloads with Webrat”

  1. The Ruby Toolbox: Browser testing on September 10th, 2009 10:07

    Kramer auto Pingback[...] Testing binary downloads with Webrat 1 day ago [...]

  2. Emphasized Insanity: Bag O' Links - 11/9/2009 on September 11th, 2009 18:34

    Kramer auto Pingback[...] Testing binary downloads with webrat – a suggestion for a possible way to test downloads. [...]

  3. Ennuyer.net » Blog Archive » Rails Reading - Sept 10, 2009 on October 29th, 2009 12:24

    Kramer auto Pingback[...] Testing binary downloads with Webrat : Witold Rugowski aka NetManiac [...]

  4. The Ruby Reflector - Webrat on July 27th, 2010 2:27

    Kramer auto Pingback[...] Testing binary downloads with Webrat By Witold Rugowski of NetManiac 11 months ago. [...]

  5. Old Nabble - RubyOnRails Users - Test files downloads with Cucumber on November 29th, 2010 19:44

    Kramer auto Pingback[...] 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 [...]

  6. View topic - Test files downloads with Cucumber :: For Linux & Unix Server Administrators and Developers :: BlueQuartz.US on February 3rd, 2011 3:23

    Kramer auto Pingback[...] 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 [...]

  7. [Rails] Re: Test files downloads with Cucumber on April 18th, 2011 11:25

    Kramer auto Pingback[...] 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