Rspec render_template无法按预期工作

时间:2013-04-13 22:40:59

标签: ruby-on-rails ruby-on-rails-3 rspec

我有测试用户注册的规范

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

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

0 个答案:

没有答案