Arthur, I forgot to mention that the default controllers that get generated by merb-gen resource don't return NotAcceptable (406) on failing requests. You will have to add that yourself to the actions in question. Again, have a look at http://github.com/snusnu/merb_resource_controller/tree/master/lib/merb_resource_controller/actions.rb to see how I do that. Basically, it boils down to providing the appropriate :status option to render/display
cheers snusnu On Sun, Dec 14, 2008 at 05:57, Martin Gamsjaeger <[email protected]> wrote: > Hey Arthur, > > Have a look at the specs inside > http://github.com/snusnu/merb_resource_controller/tree/master to see > how I do this. Not sure if that's the best, but it basically relies on > returning appropriate HTTP status codes so it should be quite ok. > > cheers > snusnu > > On Sun, Dec 14, 2008 at 04:27, Arthur Zapparoli <[email protected]> wrote: >> >> In my sucessfull DELETE, there's no mock. In fact, I don't use mocks >> on all of my other tests. I know how this can make my tests brittle. >> >> But I couldn't figure how to test this: "if anything goes wrong with >> the DELETE, raise InternalServerError" without mocking. >> >> And, merb-gen do not creates tests for failing. It only create tests >> for successful delete. >> >> Arthur Zapparoli >> http://merb-br.org >> http://arthurgeek.net >> >> On Sun, Dec 14, 2008 at 12:52 AM, Tony Mann <[email protected]> wrote: >>> You don't need to use mocks. To see how to do what you want, use merb-gen >>> resource_controller to make controller, and then look at its specs. The >>> specs use pure CRUD to create and delete resources, making it a more >>> realistic test of the system. >>> >>> The merb community frowns on mocks, and once you ditch them, you will see >>> why. Suddenly your tests fail when the actual system fails! >>> >>> ..tony.. >>> >>> On Sat, Dec 13, 2008 at 2:25 PM, Arthur Zapparoli <[email protected]> >>> wrote: >>>> >>>> Hi everyone, >>>> >>>> How to test a failing request on my controllers? >>>> >>>> Eg: I want to test a sucessfull DELETE, and a failing DELETE too. >>>> >>>> I did this using mocks, but I wan't to know if there's any othr way to >>>> test this. >>>> >>>> Here's my code: >>>> >>>> describe "a failing DELETE", :given => "a foo exists" do >>>> >>>> before(:each) do >>>> Foo.should_receive(:get).and_return(@foo = Foo.first) >>>> @foo.should_receive(:destroy).and_return(false) >>>> end >>>> >>>> it "do not deletes the foo from the database" do >>>> lambda { delete_neighborhood(Foo.first) }.should_not change { >>>> Foo.count } >>>> end >>>> >>>> it "raises a 500 InternalServerError" do >>>> @response = delete_neighborhood(Foo.first) >>>> @response.status.should == 500 >>>> end >>>> end >>>> >>>> And, controller: >>>> >>>> def destroy(id) >>>> @foo = Foo.get(id) >>>> raise NotFound unless @foo >>>> if @foo.destroy >>>> redirect resource(:foos), :message => {:notice => "Foo >>>> sucessfully deleted"} >>>> else >>>> raise InternalServerError >>>> end >>>> end >>>> >>>> >>>> Arthur Zapparoli >>>> http://merb-br.org >>>> http://arthurgeek.net >>>> >>>> >>> >>> >>> > >>> >> >> >> >> > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "merb" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/merb?hl=en -~----------~----~----~----~------~----~------~--~---
