Test rails model with Cucumber?

Hi all,

Can I test my rails model with cucumber? Or is this not what cucumber
is used for? If it is, can anyone lead me to documentation on how to
use cuke to test Rails model please. I have read the cuke wiki rails
section, but I still can not understand how to use cuke to test my
model.

Many thanks for your help.


Certified Scrum Master
http://blog.scrum8.com | http://jobs.scrum8.com |
http://twitter.com/scrum8

Joshua P. wrote:

Hi all,

Can I test my rails model with cucumber? Or is this not what cucumber
is used for? If it is, can anyone lead me to documentation on how to
use cuke to test Rails model please. I have read the cuke wiki rails
section, but I still can not understand how to use cuke to test my
model.

I don’t see how this is a good use of Cucumber. Cucumber seems to be
best for testing user interface.

Many thanks for your help.


Certified Scrum Master
http://blog.scrum8.com | http://jobs.scrum8.com |
http://twitter.com/scrum8

Best,

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

Cucumber is meant to be used for integration testing. You should use
one of the unit test frameworks (rspec, shoulds, test::unit) to test
your models specifically.

–Tim R.

Joshua P. wrote:

Hi all,

Can I test my rails model with cucumber? Or is this not what cucumber
is used for? If it is, can anyone lead me to documentation on how to
use cuke to test Rails model please. I have read the cuke wiki rails
section, but I still can not understand how to use cuke to test my
model.

Many thanks for your help.


Certified Scrum Master
http://blog.scrum8.com | http://jobs.scrum8.com |
http://twitter.com/scrum8

Actually, I agree with Tim R., cucumber is meant as a Business
Readable Behavior Description language, but I don’t like non-answer
answers.

It absolutely CAN be used to test models, although it is not the best
option, currently IMHO the best choice at least for Rails models, is
Rspec+Shoulda alone, but here’s an exmaple of one way to do it (on top
of rspec and shoulda):

http://www.pastie.org/656364

I hope it answers your question, although is extremely verbose for a
model unit test, where a simple rspec test would suffice and be much
more expressive for a programmer, after all unit tests are not meant to
be seen or used by customers, in that area, Cucumber is the way to go
right now.

IMHO Cucumber is an excellent tool to use to on top of rspec to do unit
testing.

Dear Joshua,

Doing unit tests with cucumber has not yet been approved as a best
practice,
but don’t let that stop you from experimenting.

Cucumber is no substitute for rspec , it’s a complement, a
way of writing tests in a more natural language, using rspec’s power
underneath.
Thus, it is not only suited for integration tests, but for view test,
database tests,
and anything else that you can think of.

Jim W. has started an implementation of unit test with cucumber.

I recommend you simply write in cucumber what you need to test,
and figure out how to make it reusable to other models.

A good friend has started an implementation of reusable steps
in Spanish, soon it will be available in English too.

All the best!

Raimond G.