[rspec-users] RSpec and Factory Girl: Destroying an object
mailinglists at patmaddox.com
Fri May 14 11:27:30 EDT 2010
On May 14, 2010, at 8:09 AM, Daniel Salmeron Amselem wrote:
> I have a problem when testing the deletion of a record from the
> database. I am using RSpec methods to check if my account object is
> being destroyed.
> The factory creates an account object and saves it into the DB. Also
> the two should_receive expectations seem to work.
> The problem is that when checking the database after the
> "delete :destroy, :id => account" line, the account record still
> it "should be able to destroy an account" do
> account = Factory(:account)
> delete :destroy, :id => account
> Account.all.should == 
> response.should be_success
> response.should render_template("new")
> # app/controllers/accounts_controller.rb
> def destroy
> account = Account.find(params[:id])
> redirect_to accounts_path
> I hope someone can help me on this one.
You've mocked out the call to destroy, which hides the original implementation. Pick either a state-based test (checking the database, don't use mocks) or mock-based test, but don't mix and match.
More information about the rspec-users