0
有没有办法来重构这个避免重复:我如何可以重构这些断言,以避免重复
post :create, user: attributes_for(:user)
鉴于第一个断言需要将其包装在expect
块,我不知道看到一种将它移动到before
块的方法。很明显,我可以将最后两个断言封装在context
或describe
块中,并使用它自己的before
块,但这不太合适。
context 'with valid attributes' do
it 'should create a new User and save it to the database' do
expect {
post :create, user: attributes_for(:user)
}.to change(User, :count).by(1)
end
it {
post :create, user: attributes_for(:user)
should redirect_to(user_path(assigns[:user]))
}
it {
post :create, user: attributes_for(:user)
should set_the_flash[:notice]
}
end