为什么水豚不能直接提交采取行动

为什么水豚不能直接提交采取行动

本文介绍了为什么水豚不能直接提交采取行动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在观看Michael Hartl的Rails教程,在第9.2.2章中,Hartl说我们不能使用capybara直接向模型发出put / patch请求,

I was watching Michael Hartl's Rails tutorial, In chapter 9.2.2, Hartl says that we can't use capybara to issue put/patch requests directly to a model,

这是测试代码:

describe "for wrong users" do
  let(:user) { FactoryGirl.create(:user) }
  let(:wrong_user) { FactoryGirl.create(:user, email: "[email protected]") }
  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
end

valid_signin如下所示:

and valid_signin is like this, intially:

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

这些测试无效,因为当我们发出认沽要求时西方,我们不能使用capybara来做到这一点。

These tests don't work, as when we issue a put request, we can't use capybara to do this.

是这样吗,我们不能使用capybara来测试任何put / patch请求?以及在需要测试放置/补丁请求而不能使用水豚的时候应该做什么?

So is it like this, that we can't use capybara to test any put/patch requests? And what we should do in general when we need to test put/patch requests and we can't use capybara?

推荐答案

水豚用于行为驱动程序开发。谁的行为?人类。

Capybara is for Behaviour Driver Development. Who's behaviour? Human beings.

人类补丁可以吗?他可以投入吗?他不能。只有计算机可以。

Can a human being patch? Can he put? He can't. Only computers can.

人类可以参观 fill_in click_button ?是的,他能。这就是Capybara的目的。

Can a human being visit, fill_in, click_button? Yes he can. This is what Capybara for.

最重要的是,将计算机的动作纳入单元测试和控制器测试中,在Capybara的集成测试中模仿人类。

Bottom line, put computers' actions into unit testing and controller testing, mimic human beings in integration testing by Capybara.

这篇关于为什么水豚不能直接提交采取行动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 01:48