Hi! Sorry for no articles for a while, I’m pretty busy with Railsware activities currently. Anyway, while doing some internal product, I’ve come to a need in aspects for rspec.
Why do I need this? There are contexts in rspec already, you can say. True. But what these context are intented for? Lets cite rspec documentation: It is a metaphor for the context in which you will run your executable example – a set of known objects in a known starting state. Right. And there are plenty of specifications that run against given context. But if you have a relatively large project, you’ll find that your specifications become messy even within one context.
That’s why I’ve tried to add aspects. They are usually 1-2 words describing primary aspect of functionality you’re testing. It could be “printing”, or “versioning”, or “tracking changes”, or “validations”. Let me show how it looks now:
context "New Document instance" do
setup do
@document = Document.new
end
aspect "versioning" do
specify "should have no versions" do
@document.should_have(0).versions
end
end
end
Easy? I bet! I’ve done quick-n-dirty implementation for this feature and started improving structure of my tests. This implementation requires ActiveSupport at the moment but could be easily ported to pure Ruby. I’m just too lazy tonight.
Any thoughts?
Update Thanks to Michael, I’ve updated algorithm to support nested aspects. You can use new version to enjoy nested aspects.




