0
一直試圖弄清楚這一點,但似乎不能走綠色。這裏是RSpec的錯誤,我越來越:後創建用戶計數失敗的測試。應該改變1,但被改變了0
1) UsersController POST create with valid parameters creates a new user
Failure/Error: expect {post :create, user}.to change(User, :count).by 1
count should have been changed by 1, but was changed by 0
# ./spec/controllers/users_controllers_spec.rb:36:in `block (4 levels) in <top
(required)>'
這是我在users_controllers_spec相關測試:
describe UsersController do
let(:user) {FactoryGirl.create :user}
context 'POST create' do
context 'with valid parameters' do
before {post :create, user}
let(:user) {FactoryGirl.build :user}
it 'creates a new user' do
expect {post :create, user}.to change(User, :count).by 1
end
it {should respond_with 200}
end
,這裏是我的users_controller創建方法:
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome #{@user.name.capitalize}! Please complete your profile."
redirect_to profile_path(current_user)
else
render :new
end
end
而且,這裏是我的factories.rb文件:
FactoryGirl.define do
factory :user do
name "John"
email "[email protected]"
password "password"
password_confirmation "password"
end
end
我錯過了什麼?我覺得這是非常明顯的事情,但我似乎無法弄清楚。任何幫助將非常感激。
你有任何'用戶'驗證,將阻止創建多個用戶具有相同的名稱,電子郵件等? –
是的。我有一個唯一性驗證電子郵件。 – LeDeep