On 7/11/07, Ashley Moran <[EMAIL PROTECTED]> wrote: > > On 11 Jul 2007, at 15:00, Pedro Del Gallego wrote: > > > Thats my biggest problem with rspec, (I'm a non english speaker > > working in a German/English environment) It would be great a guide or > > a tips list to make our specs more readebles, Something like 10 > > English tips to improve your specs readability ;) > > > Don't think I can come up with 10 off the top of my head but I always > told Pawel to follow the rule "phrase descriptions as GIVEN WHEN > THEN". There's plenty of better examples on this list and elsewhere, > but basically if I have an idea like this: > > A cow prodded with a stick should moo > > I think: > GIVEN="a cow", WHEN="prodded with a stick", THEN="moo" > > and turn it into this code: > describe Cow do > before(:each) do > @cow = Cow.new > end > it 'should say "moo" when sent prod_with_stick' do > @cow.prod_with_stick.should == "moo" > end > end > > It doesn't apply rigidly to every situation, but 90% of the time, if > I keep chanting GIVEN WHEN THEN I write clean, focussed specs. The > rest is mainly vocabulary (although sometimes it can be hard to > phrase something clearly).
I've been in that habit too. In general, I want the GIVEN expressed in the String passed to describe and/or before(:each). The WHEN and THEN should be in the example. As Ashley suggests, this isn't 100% of the time, but I find that the more I stick to this the easier it is to grok everything when looking back. Also, I try to stick to one WHEN and one THEN per example. This means that if there are mocks involved, my examples generally look like this: it "should foo when bar" do collaborator.should_receive(:baz) thing.bar end OR it "should foo when bar" do thing.bar thing.baz.should == something end BUT NEVER it "should foo when bar" do collaborator.should_receive(:baz) thing.bar thing.fu.should == something end FWIW. Cheers, David > > Ashley > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users