Hi everyone, I’m just now really starting to look into Agile
Development, and so I’m trying to gauge what the Rails community’s
preference is in regards to using RSpec versus the built-in Test::Unit.
I haven’t really delved much into testing in the past, I’m sad to say,
but I understand why it’s beneficial to writing maintainable code and I
wish to start in order to become a better developer.
I am starting a new project for a potential business opportunity, and I
would really like to use more agile techniques when designing it to A)
Improve the quality of the code, and B) Improve my own skills since by
and large my experience has been of the “Just hack together something
that works” variety (not by choice, of course).
The biggest hurdle I seem to be facing is that I never seem to know what
to test for. I’ve read a little about Test-Driven Development in the
past, but when I try to do it I always think that I’m testing things
which don’t matter; the blogs and articles I’ve read seem to give both
sides of the coin in regards to this - I’ve seen some say that it’s bad
to test the built-in functionality of Rails (because those would have
their own tests anyway and if something like ActiveRecord, for example,
doesn’t work the right way internally then something is wrong with Rails
itself, and not your code). I’ve also seen a lot of examples that DO
test the built-in functionality, although that might be because they are
tutorials.
In any event, I recently learned about RSpec (actually it was from
reading the book “The Rails Way”, which suggests to use RSpec instead of
Test::Unit), and while Behavior-Driven Development seems a little easier
to grasp due to the English-like syntax, it brings a whole new problem:
Half the time I’m not sure at first what the behavior should be to
begin with - what I mean is that I know in my head what I want to be
able to do, but I have a hard time fleshing it out into a spec. The BDD
style also seems to be heavily in favor of mocking and stubbing as
opposed to Test::Unit which has a test database, which I’ve heard about
but never done so is a little confusing as well. It doesn’t “feel” like
I’m really testing things, since most examples I’ve seen will stub out
the find methods to return predefined values… so how do you know that
it’s returning what you need? I know that you can use fixtures with
RSpec, but I’ve heard that this is basically tacked on instead of
assumed like with the built-in stuff.
As a general rule I try to follow the best practices of the community,
so I can learn from more advanced developers and also have a comparable
skillset for the future. In this case, however, I’m not really sure
which path to take.
Any advice/suggestions would be greatly appreciated. I am still sort of
learning how Rails works… coming from a .NET background, the
conventions are a little confusing at first and seem a little
restrictive, but overall I am enjoying it.
- Wayne