0
所以我試圖首次使用Rspec在我的應用程序上測試模型,但我似乎無法使其工作。我使用FactoryGirl創建模型的實例。這裏是我的規格:在模型測試中Rspec的should_receive的另一個問題
describe 'adding a model instance' do
before :each do
@fake = FactoryGirl.create :user
end
it 'should add a new user to the database' do
User.should_receive(:create).with(@fake)[email protected])
end
end
這裏是我的模型:
class User < ActiveRecord::Base
attr_accessible :username, :name, :email, :email_confirmation, :password, :password_confirmation, :bio
has_many :comments #comments user has posted on ideas
has_many :commented_ideas, :class_name => 'Idea', :through => :comments #ideas user has commented on
has_many :ideas #ideas user has posted
validates :password, :email, :confirmation => true
validates :username, :email, :password, :name, :presence => true
# validates :username, :email, :unique => true
end
和錯誤,我越來越:
Failure/Error: User.should_receive(:create!).with('username' => 'testUser', 'user_id' => "1").and_return(true)
(<User(id: integer, username: string, name: string, email: string, password: string, created_at: datetime, updated_at: datetime, bio: text) (class)>).create!({"username"=>"testUser", "user_id"=>"1"})
expected: 1 time
received: 0 times
是否有人可以解釋爲什麼這不工作?