Topic: Rspec controller problem?

Any idea why this would fail?

  before(:each) do
    @user = mock("user")
   
    @user.stub!(:save!).and_return(false)
    User.stub!(:new).and_return(@user)

  end

  it "should tell the User model to create a new user on POST to create" do
    User.should_receive(:create).with({"login" => 'josh'}).and_return(@user)
   
    post 'create', :user => {:login => 'josh'}
  end


with this error message

1)
Spec::Mocks::MockExpectationError in 'UsersController should tell the User model to create a new user on POST to create'
User expected :create with ({"login"=>"josh"}) once, but received it 0 times

edit: arg, I just figured it out!

Since I'm doing the (restful) style of authentication, the User model should recieve the new action, and then pass the paramters to the create action.

Duh!

  it "should tell the User model to create a new user on POST to create" do
    User.should_receive(:new).with({'login' => 'josh'}).and_return(@user)

    post 'create', :user => {'login' => 'josh'}
  end


SUCCESS!

Last edited by DFischer (2007-05-14 17:50:38)

http://danielfischer.com - Personal Web-Technology-Blog, Los Angeles.