This is a little off topic, but I use rSpec and I¹m starting to question the
quality of my specs. In my research and attempt to learn how to write
better specs, I¹ve came across a few things that I¹d like to discuss.
I¹m having more and more difficulty understanding BDD. The more I read and
the more I watch, the more questions I come up with. Let me just ask a
couple of general questions to start this off.
Is shoulda¹ actually following the principals of BDD? But, I guess that¹s
not really a good question. Is shoulda¹ encouraging it¹s users to follow
the principals of BDD? I see all of the macros like:
should_belong_to
should_require_attributes
To me, that is not BDD. Basically that¹s just testing whether or not your
model contains a certain code fragment. But, that brings me to my next
question.
Is BDD even possible with Rails? (I think it is, but I ask myself that more
and more lately)
I just picked a random model in the application I¹m currently working on.
The Picture¹ model. I use the attachment_fu plugin, which helps this model
handle pictures (it creates thumbnails, validates sizes, etc.) I wiped out
all the code I had and all the specs I had. I started from scratch:
----------------------------------
class Picture < ActiveRecord::Base
end
----------------------------------
The first piece of code I would write if I wasn¹t using BDD, would be:
----------------------------------
class Picture < ActiveRecord::Base
validates_as_attachment
end
----------------------------------
Which basically handles all of my validation. So, from a BDD perspective,
how do I spec that? I know, I know, I should be writing the specs first.
But, what do I do about these helpers that come with plugins. Do I write a
spec:
----------------------------------
describe Picture, with a blank filename¹ do
before(:each) do
@picture = Picture.new valid_picture_attributes.except(:filename) # This
uses some rSpec helpers
end
it do
@picture.should_not be_valid
end
end
-----------------------------------
So, the most simple way to solve that would be (this is part of what
validates_as_attachment¹ does):
----------------------------------
class Picture < ActiveRecord::Base
validates_presence_of :filename
end
----------------------------------
But, now what, I¹m going to reverse engineer this plugin¹s helper? I¹ll
just spec it all out and eventually refactor and put the
validates_as_attachment¹ back? Or, maybe since this is a plugins helper I
don¹t even need to test any of this. It¹s the author of the plugin¹s
responsibility. This is were my brain enters an infinite loop (one example
anyway, hehe). I just can¹t seem to nail down the workflow when specing
rails apps. I also have a hard time determining what to spec.
I know I asked a lot of questions, but basically I¹m just trying to find out
if people are actually following the BDD principals strictly when writing
Rails apps. If you are can you give me some insight in the above example?
Thanks,
Matt Lins
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users