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