Here is the model I'm using, I simplified it a bit to the simplest form, which still does not match my example:
class User < ActiveRecord::Base after_create :setup_lists def setup_lists List.create(:user_id => self.id, :name => "current") List.create(:user_id => self.id, :name => "master") end end
And I would like to give an example as follows:
require 'spec_helper' describe User do before(:each) do @user = Factory(:user) end describe "#setup_lists" do before(:each) do List.stub(:create).with(:name => "current") List.stub(:create).with(:name => "master") it "creates a new master list" do List.should_receive(:create).with(:name => "master") end it "creates a new current list" do List.should_receive(:create).with(:name => "current") end end end
I expected this to be normal, but I was left with the following error:
Failures: 1) User#setup_lists creates a new master list Failure/Error: List.should_receive(:create).with(:name => "current") (<List(id: integer, name: string, created_at: datetime, updated_at: datetime, user_id: integer) (class)>).create({:name=>"current"}) expected: 1 time received: 0 times # ./spec/models/user_spec.rb:44 2) User#setup_lists creates a new current list Failure/Error: List.should_receive(:create).with(:name => "master") (<List(id: integer, name: string, created_at: datetime, updated_at: datetime, user_id: integer) (class)>).create({:name=>"master"}) expected: 1 time received: 0 times # ./spec/models/user_spec.rb:48
Can someone help me understand why this is happening?
source share