Expecting arbitrary method calls in a particular order in RSpec
posted: July 13th, 2008 · by: Sven
For a spam protection feature in a project I’m currently working on I started out specifying the behaviour of a filter chain that I was planning to implement. Specifically, I wanted to specify that the filter chain would call the filters in the expected order.
Looking at the RSpec documentation for expecting method calls on mock objects I didn’t found this usecase mentioned at first. It turns out to be pretty easy with RSpec mocks though.
#should_receive takes a block that (according to the documentation) is meant to be used to compute return values. This block is called within the specification’s scope so it can be used to track the method call order.
My initial spec looks like this (simplified for clarity):
it "runs the filters in the correct order" do
log = []
@default.should_receive(:run){ log << :default }
@akismet.should_receive(:run){ log << :akismet }
@defensio.should_receive(:run){ log << :defensio }
@chain.run
log.should == [:default, :akismet, :defensio]
end
Update
After some discussion on the RSpec users mailinglist Ashley Moran pointed out a more elegant solution to this which also uses the should_receive block:
it "runs the filters in the correct order" do
@default.should_receive(:run) do
@akismet.should_receive(:run) do
@defensio.should_receive(:run)
end
end
@chain.run
end
Thanks :)
wicktor said November 26th, 2008 at 05:05 PM ¶
That instructions were very helpful.
jgeiger said January 23rd, 2009 at 09:32 PM ¶
Actually if you go down a bit on the RSpec documentation for expecting method calls on mock objects page, there is a way to set the order.
ddsgd said March 21st, 2011 at 06:29 AM ¶
How to Convert AVCHD films to AVI
URL?http://www.wondershare.com/avchd/convert-avchd-to-avi.html Troubles we may possibly have encountered to take satisfaction in and reveal AVCHD films with friends:
That’s true, the AVCHD structure is not accepted by lots of players, and also this kind of structure cannot be uploaded to internet which prevents film sharing. I’ve searched near to some great offer and uncover an simplest alternative finally. The simplest way can be to convert avchd to avi or other standard formats.
The alternative we are able to consider to solve them: An AVCHD to AVI Converter is needed. Please click to obtain avchd to avi converter, set up and run it. Step one Get AVCHD films from AVCHD Camcorder to PC
Connect the AVCHD Camcorder for the PC using a USB cable. when attached and powered on, the camcorder should seek out the desktop like a brand brand new disk. It is desirable which you duplicate the films for the PC’s hard-drive earlier to converting avchd to avi or editing it. Step 2. fill AVCHD camcorder videos
Click “Add Video” or just drag & squirrel away your AVCHD camcorder films using the document checklist directly, you can very easily include AVCHD camcorder videos.
Load AVCHD camcorder videos Step 3. find AVI as output format
Select AVI as output structure away from your categorized output formats checklist in “Profile” drop-down checklist and specify the output list to preserve your converted records in “Output” drop-down list.
Select Convert AVCHD films to AVI output format Step 4. start to convert avchd to avi
After every little thing is done, strike “Start” key to convert avchd to avi. And all the things can be achieved at quickly demand and higher quality. The conversion demand often is dependent for the genuine film sizing as well as your PC configuration. as well as the output best quality is great.
After converting avchd to avi, now you can upload these AVI films to internet or view them with house windows advertising Player/Movie Maker to reveal them jointly with your friends. The complete method is easy, and you also can possess a try of the AVCHD to AVI Converter to how to convert avchd to avi and reveal your delighted instant easily.
Tips: Why we choose AVI format? As we realize that AVI structure is among the probably the most standard formats, that is broadly accepted by the majority of players. as well as the best quality of AVI film is great. using the sake of reputation and compatibility, AVI is regarded as probably the most advantageous choice. Therefore, you only should convert AVCHD to AVI, after which you can very easily reveal your AVCHD camcorder videos.
Cams said March 30th, 2011 at 07:45 PM ¶
I had a problem with this code. It kept giving errors:
mymock.shouldreceive(:one).ordered mymock.shouldreceive(:two).ordered mymock.shouldreceive(:three).ordered
side sleeper pillow said April 22nd, 2011 at 07:04 AM ¶
Nicely written article, Knowledgeable and informative post. I’m really glad I came my way along your site. Keep posting, I really like the whole topic. Thanks for sharing.
Okey oyunu said May 12th, 2011 at 03:37 PM ¶
Tüm dünya artik okey oyunu oynuyor. Yillardir bir çok oyun programi olmasina ragmen, içlerinden en güzeli olarak nitelendirebilecegimiz tek bir site göze çarpmaktadir. Diger tüm okey oyunu programlarinin aksine ücretsiz olmasi ve 3 boyutlu olarak hizmet vermesi mükemmel bir gelismedir. Sizlerde www. okey-oyunu.com adresinden bu essiz okey oyununu indirebilirsiniz. Kullanimi çok basit ve Türkçe dil seçenegi ile kolaylikla oyuna baslayabilirsiniz. Ister kendi ülkenizden, isterseniz dünyanin tüm farkli bölgelerinden dilediginiz oyun odalarini seçerek, oyuna hemen baslayabilirsiniz. Okey oyunu oynamak için artik arkadas bile aramaniza gerek kalmadan, bilgisayarinizdan 100 binlerce üye ile online olarak okey oyununu oynamanin zevkine varabilirsiniz.
Rob said May 13th, 2011 at 12:55 PM ¶
Thank you for the helpful filtering solution:
it “runs the filters in the correct order” do @default.should_receive(:run) do @akismet.should_receive(:run) do @defensio.should_receive(:run) end end @chain.run end
Thanks sven:)
Rob ( oil spill kits guru )
p said May 21st, 2011 at 05:06 PM ¶
porno said May 23rd, 2011 at 10:43 AM ¶
I do agree with all of the ideas you have presented in your post. They’re really convincing and will definitely work. Still, the posts are too short for newbies. Could you please extend them a bit from next time? Thanks for the post.
porno said May 23rd, 2011 at 10:44 AM ¶
good comment. thanks you friends.
I’ve surfed the net more than three hours today, however, I haven’t found such useful information. Thanks a lot, it is really useful to me