我有两个模型:Post 和 User(Devise)。我正在测试 Post 控制器。
describe "If user sign_in" do
before(:all){
@user = Factory(:user)
}
it "should get new" do
sign_in @user
get 'new'
response.should be_success
response.should render_template('posts/new')
end
it "should create post" do
sign_in @user
post 'create', :post => Factory(:post)
response.should redirect_to(post_path(:post))
end
end
但第二个测试失败了:
错误/错误:post 'create',:post => Factory(:post) ActiveRecord :: RecordInvalid: 验证失败:电子邮件已被占用,电子邮件已被占用,用户名已被占用
我该怎么办?