Test files downloads with Cucumber

Hi everybody:

I’m writing tests with Cucumber and Capybara and I just want to know if
there is anyway to check if the download links and/or the files of my
aplication are OK. An example scenario would be the following one:

Scenario: Checking links
Given I am logged in as …
When I follow …
And I click on “Download”
Then I should download “File1.zip”

Is it possible to do or is there any other way to do something similar?
Thanks.

John Wu wrote in post #961880:

Hi everybody:

I’m writing tests for a future application with Cucumber and Capybara
and I just want
to know if there is anyway to check if the download links and/or the
files are OK.

Why do you want to use Cucumber to test that the files are OK? It seems
to me that this is properly done in your model specs, by testing the
methods that generate the files.

An example scenario would be the following one:

Scenario: Checking links
Given I am logged in as …
When I follow …
And I click on “Download”
Then I should download “File1.zip”

Is it possible to do or is there any other way to do something 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
[email protected]

Marnen Laibow-Koser wrote in post #961883:

Why do you want to use Cucumber to test that the files are OK? It seems
to me that this is properly done in your model specs, by testing the
methods that generate the files.

Hi, thank you very much for the answer. Sorry for the explanation, by OK
I mean the correct file (not other), I´m not talking about correct size
or whatever.

At the moment, using the name to check the file is enough. By the way,
do you know anyway to check if a sent mail have an attachment using
Cucumber? Thanks again

John Wu wrote in post #961894:

At the moment, using the name to check the file is enough.

OK. Then you presumably already know how to do that.

By the way,
do you know anyway to check if a sent mail have an attachment using
Cucumber? Thanks again

You’re asking the wrong questions, I think. The question is not “how to
test for … using Cucumber?”; the question is “how to test for …?”.
Remember, there’s nothing magical about Cucumber steps; they can call
any Ruby code you like.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

John Wu wrote in post #961887:

Marnen Laibow-Koser wrote in post #961883:

Why do you want to use Cucumber to test that the files are OK? It seems
to me that this is properly done in your model specs, by testing the
methods that generate the files.

Hi, thank you very much for the answer. Sorry for the explanation, by OK
I mean the correct file (not other), I´m not talking about correct size
or whatever.

How do you plan to check that? Name? MD5 hash?

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

John Wu wrote in post #961900:

Marnen Laibow-Koser wrote in post #961899:

John Wu wrote in post #961894:

At the moment, using the name to check the file is enough.

OK. Then you presumably already know how to do that.

In fact, that’s the main question because I have no idea how to do that.

You’ll probably want to download the file to a temporary directory
(Tmpdir will come in handy here), which you know is blank at the
beginning of the test, then check the contents of the directory after
the test. There may be other approaches.

Capybara may have a canned way of doing this. Check the docs.

By the way,
do you know anyway to check if a sent mail have an attachment using
Cucumber? Thanks again

You’re asking the wrong questions, I think. The question is not “how to
test for … using Cucumber?”; the question is “how to test for …?”.
Remember, there’s nothing magical about Cucumber steps; they can call
any Ruby code you like.

Sorry, my bad again.

Oh, it’s not “your bad”; I’m just trying to remind you that you probably
know a lot of these answers already.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Marnen Laibow-Koser wrote in post #961899:

John Wu wrote in post #961894:

At the moment, using the name to check the file is enough.

OK. Then you presumably already know how to do that.

In fact, that’s the main question because I have no idea how to do that.

By the way,
do you know anyway to check if a sent mail have an attachment using
Cucumber? Thanks again

You’re asking the wrong questions, I think. The question is not “how to
test for … using Cucumber?”; the question is “how to test for …?”.
Remember, there’s nothing magical about Cucumber steps; they can call
any Ruby code you like.

Sorry, my bad again.