我在看Michael Hartl的Rails教程,在第9.2.2章中,Hartl说我们不能使用capybara直接向模型发出put/修补程序请求,
这是测试代码:
describe "for wrong users" do
let(:user) { FactoryGirl.create(:user) }
let(:wrong_user) { FactoryGirl.create(:user, email: "wrong@example.com") }
before { valid_signin user}
describe "when submitting a PATCH request to users#update" do
before { patch user_path(wrong_user) }
specify { expect(response).to redirect_to root_path}
end
endvalid_signin是这样的,很遗憾:
def valid_signin(user, options = {})
visit signin_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end这些测试不起作用,因为当我们发出put请求时,我们不能使用水豚来完成这个任务。
那么,难道我们不能用水豚来测试任何put/修补程序请求吗?当我们需要测试put/修补程序请求而不能使用水豚时,我们应该做什么呢?
发布于 2013-08-29 07:36:03
水豚是负责行为驱动程序开发的。谁的行为?人类。
一个人能patch吗?他能put吗?他不能。只有电脑才能。
一个人能visit,fill_in,click_button吗?是的他可以。这就是凯巴拉的目的。
最后,将计算机的动作应用到单元测试和控制器测试中,模拟人的集成测试。
https://stackoverflow.com/questions/18504669
复制相似问题