0

我有一个测试用户注册的规范

describe '#POST do_register' do
  context 'with valid parameters' do
    before { post :do_register, user: attributes_for(:new_user) }

    it 'assigns a persisted @user' do
      assigns(:user).should_not be_new_record
    end

    it 'redirects to login path' do
      response.should redirect_to(login_path)
    end

    it 'sets user profile as member' do
      assigns(:user).profile.should be_a(Member)
    end
  end

  context 'with invalid paramaters' do
    before { post :do_register, user: attributes_for(:new_user, username: nil) }

    it 'assigns a new @user' do
      assigns(:user).should be_new_record
    end
    it 'renders register form' do
      response.should render_template('register')
    end
  end
end

我期待得到一个错误,因为失败时我没有register在控制器中呈现模板save

def do_register
  ...

  if @user.save
    redirect_to(login_path)
  end
end

但是我根本没有收到任何错误,并且示例通过了。我错过了什么吗?

4

0 回答 0