RSpec: Expectation on model's not working while testing controller

Posted by gmile on Stack Overflow See other posts from Stack Overflow or by gmile
Published on 2010-04-29T15:25:14Z Indexed on 2010/04/29 18:27 UTC
Read the original article Hit count: 262

I'm trying to write a functional test. My test looks as following:

describe PostsController do
  it "should create a Post" do
    Post.should_receive(:new).once
    post :create, { :post => { :caption => "ThePost", :category => "MyCategory" } }
  end
end

My PostsController (a part of it actually) looks as following:

PostController < ActiveRecord::Base

  def create
    @post = Post.new(params[:post])
  end

end

Running the test I'm always receiving a failure, which says that the Post class expected :new but never got it. Still, the actual post is created.

I'm a newbie to RSpec. Am I missing something?

© Stack Overflow or respective owner

Related posts about rspec

Related posts about ruby-on-rails