« Ruby 1.9 Standard Library Changes | Main | Just shipped tons of books (literally) »

April 28, 2008

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83451c41c69e200e55217b5b18834

Listed below are links to weblogs that reference Shoulda used this earlier:

Comments

Sam Aaron

This looks remarkably similar to the structure of rspec tests: just switch context for describe, should for it, setup for before(:each) and you're pretty much there. However, this doesn't introduce the marmite-like 'love it or hate it' syntactic sugar/vinegar that people rant about.

I think that nesting contexts like this is a great idea, and it's good to see it over on the Test::Unit side of the fence :-)

Phil

@Sam: actually it looks more like older versions of RSpec; they used context liberally, and I think setup as well. But I'm not sure if nesting was supported.

Morgan Roderick

I've been using shoulda for awhile ... I guess I should have told you about it ;-)

Nice to see that it's getting some traction, as it's very nice, and keeps your testing nice and easy to manage.

RSpec just seemed to big me when I was flirting with it, but with shoulda, the glove just fits me perfectly.

Dan Croak

I'm a dog person.

Ben

RSpec actually explicitly avoided nested contexts for quite some time - they're a more recent addition.

Sebastian

Very usefull post.

Adrian Kuhn

I wonder if what you do could also be achieved with JExample's first-class dependencies [1]. JExample runs tests based on a dependency graph, and you can run a subset/subgraph of the test. Would be a interesting exercise to port JExample to Ruby anyway ... there is certainly a nice Rubyism that can be used instead of Java's annotations.

[1] http://www.iam.unibe.ch/~scg/Research/JExample/

Robert Walker

I haven't yet landed on a testing framework for my Ruby work. I'm still pretty new to Ruby and don't have anything currently in production. I've looked at Test::Unit, but I've been investigating rSpec in much more depth. I have heard of Shoulda mentioned in passing, but I've not looked at it yet.

Before I dig too deeply, I was wondering about what people are using for mocking and stubbing with Shoulda. Apart from the nice syntactic sugar provided by rSpec, its mocking and stubbing features seem pretty powerful and very useful. I am aware of some mocking frameworks like Mocha, but is there anything built into Shoulda? If not then how easy is it to integrate Shoulda with a mocking/stubbing framework?

Chad Pytel

Robert, we use Mocha with Shoulda, and its just a matter of installing them both.

Tammer Saleh

Adrian: JExample looks pretty interesting. Basically, it combines the ideas of a test and a setup into one unit, which contains assertions and will only run the units that depend on it once those assertions pass. This feels to me like a superset of the features of Shoulda, so I'm inclined to say that there's technically nothing Shoulda can do that JExample can't.

That being said, one of the main goals with Shoulda was to create a full featured testing system built on top of the ruby Test::Unit library. This allows easy and consistent migration for existing projects. I don't think it would be possible or practical to do that with JExample.

It would, however, be very interesting to see a new ruby testing framework that follows this dependency-graph pattern.

Chad Humphries

Yep, I would agree with the earlier commenters, this has the feel of rspec from about a year ago. Nothing wrong with that though :) There macros are pretty cool, but not really any different than any of the RSpec rails matcher plugins out there.

edovale

Just a counter comment about the xUnit comment.
This is like running parametrized tests. JUnit 4 has this ability where you can pass parameter to the test method and for every provided combination the framework will give the test method a run.

Chris

I wrote tests that looked almost exactly like this a year or so ago...in RSpec. I'm not sure if Shoulda has anything like it_should_behave_like, but I'd be interested to hear a comparison of the two frameworks from someone who knows what they're talking about. I've been using RSpec for a couple years now and love it, but I've never really explored Shoulda. And yup, the Shoulda macros just look like RSpec matchers, which you can write on your own or use plugins written by others.

The comments to this entry are closed.

Now in Beta

  • Programming Ruby, 3rd Edition
    Third Edition, Covering Ruby 1.9, now available
My Photo

Pragmatic Stuff

Photos

  • www.flickr.com
    This is a Flickr badge showing public photos from pragdave tagged with pragdave_badge. Make your own badge here.