javascript请求规范失败,设计身份验证
我试图在需要身份验证(通过Desive)的web应用程序上测试一个操作。具体操作使用javascript,因此我将javascript请求规范失败,设计身份验证,javascript,ruby-on-rails,rspec,capybara,Javascript,Ruby On Rails,Rspec,Capybara,我试图在需要身份验证(通过Desive)的web应用程序上测试一个操作。具体操作使用javascript,因此我将js选项应用于规范: scenario "User wants to fax a single document", js: true do reset_email @doc = @user.documents.create(FactoryGirl.attributes_for(:document)) visit "/documents/#{@user.id}" c
js
选项应用于规范:
scenario "User wants to fax a single document", js: true do
reset_email
@doc = @user.documents.create(FactoryGirl.attributes_for(:document))
visit "/documents/#{@user.id}"
click_on "send_document_#{@doc.id}"
last_email.should eq(@doc)
end
控制器以电子邮件方式发送传真。我不知道为什么;不是我写的。无论如何,在这个特性规范的顶部(使用Capybara和Rspec),我使用
before(:each) do
# Signs in as an admin
@company = FactoryGirl.create(:company)
@subscription = FactoryGirl.create(:admin_subscription, company_id: @company.id)
@user = FactoryGirl.create(:user, company_id: @company.id)
login_as @user, scope: :user
end
文件中的所有其他规范(也需要登录)仍然通过,这让我认为它与javascript有关。因此,js
选项在Firefox中打开了一个浏览器,而页面不是正确的内容。上面说
500 Internal Server Error
undefined method `status' for nil:NilClass
我在网上搜索了一下,只找到了一个回复,上面说我的控制器中没有动作,叫做response
或action
。请放心,我没有这样的行为;只有RESTful操作和两个附加操作:
def send_document
@to = params[:to].gsub(/([() \-]+)/, '')
#The below parses the number to format it for InterFax
#It adds a "+1" to the front, and a dash in the middle
#of the number where needed.
@to = "+1"+@to[0..-5]+"-"+@to[-4,4]
@document = Document.find(params[:id])
DocumentMailer.send_document(@to, @document).deliver
render :template => false, :text => 'true'
end
def email_document
@to = params[:to]
@document = Document.find(params[:id])
DocumentMailer.email_document(@to, @document).deliver
render :template => false, :text => 'true'
end
有人能帮助理解这些错误吗?这个应用程序中有很多都使用javascript,我真的需要一种在登录时测试这些操作的方法。在不首先测试操作是否已完成的情况下,请小心检查非UI条件。当您这样做时:
click_on "send_document_#{@doc.id}"
last_email.should eq(@doc)
请记住,javascript在浏览器实例中运行,该实例与测试代码不在同一进程中。在继续之前,检查页面上是否有更新可能会有所帮助:
click_on "send_document_#{@doc.id}"
page.should have_content("Email sent") # for example
last_email.should eq(@doc)
水豚声称在等待页面元素可见方面非常聪明——YMMV
如果你的应用程序需要登录,那么你的请求规范应该使用正常的登录过程——访问登录页面,键入凭据,然后导航到要测试的页面