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
-~----------~----~----~----~------~----~------~--~---

Reply via email to