[rspec-users] specing rescue, ensure and else blocks of an Exception
Tarsoly András
tarsolya at gmail.com
Fri Oct 26 09:29:19 EDT 2007
Thanks a lot guys, this is great help, it's really appreciated, it
makes a lot more sense now.
I somehow felt that I'm not entirely on the right path when I'm doing
controller testing, and your replies and examples given here shed
some light on it.
David, I like your alternative better, since it has more structure.
Also, I'd like to ask one more question, which popped into my mind
after reviewing these examples, but it's not relating strictly into
the previous topic.
Is there some way, to say something like:
it "should" do
post :any_action, params
end
I'm using some before filters in my controllers to DRY up my code,
for example: retrieve a specific record, if params[:id] is set. This
is very useful for automatic scoping and assigning instance vars in
some controllers, which are relate to nested resources (eg.
map.resources :foo, has_many => [:bar])
The aim of this would be to DRY up the tests a little bit, since each
action always retrieves a specific set of records, and I could spec
it out in the shared model for all possible actions at once, or I am
missing something here either? :)
Thanks again for the great examples, regards:
András
On 2007.10.26., at 14:02, David Chelimsky wrote:
> On 10/26/07, David Chelimsky <dchelimsky at gmail.com> wrote:
>> On 10/26/07, Tarsoly András <tarsolya at gmail.com> wrote:
>> Take a look at http://pastie.caboo.se/111125 (reorganized from your
>> example). Note that each example is about what the controller does,
>> not what the model does. Also note that there are no "and"s in any of
>> the labels. Each example sets up one thing and describes what happens
>> when the action is invoked based on those conditions.
>>
>> HTH,
>> David
>
> Here's an alternative broken down into more granular specs:
> http://pastie.caboo.se/111130.
>
> Generally I find that I don't break up my controller specs like that,
> but I break up specs for models like that all the time, so maybe I
> should be doing them this way :)
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
--
Tarsoly András
tarsolya at gmail.com
More information about the rspec-users
mailing list