ruby on rails-请求javascript规范失败,设计身份验证
ruby on rails - Request specs for javascript failing, devise authentication
我正试图在一个需要身份验证的web应用程序上测试一个操作(通过Devise)。具体操作使用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}"
click_on "send_document_#{@doc.id}"
last_email.should eq(@doc)
end
控制器以类似电子邮件的方式发送传真。我不知道为什么;我没有写。无论如何,在这个功能规范的顶部(使用带有Rspec的Capybara),我使用进行身份验证
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)
Capybara声称在等待页面元素可见方面非常聪明——YMMV。
如果你的应用程序需要登录,你的请求规范应该使用正常的登录过程——访问登录页面,键入凭据,然后导航到页面进行测试。
相关文章:
- 添加@javascript标记时,Cucumber中的HTTP身份验证失败
- postmates api的AJAX中的HTTP身份验证失败
- Spring Security中的基本身份验证(身份验证失败消息)
- 将变量从jQuery传递到WebMethod(身份验证失败)
- Django 身份验证:CSRF 失败
- jQuery 基本身份验证失败
- MongoError: 身份验证失败.- 连接到MongoLab时出现问题
- 对passportjs+Node.js+Express.js Rest API调用成功身份验证和失败的路由处理程序
- Gapi 的身份验证弹出窗口立即关闭,并失败并显示 401 错误
- 通过令牌进行身份验证,如果令牌失败,则使用Passport通过会话进行身份验证
- Sails.JS-NTLM身份验证失败时重试
- Phonegap + Sencha + Android: ajax请求与基本访问身份验证失败
- 对firebase的多个自定义身份验证请求失败
- fetch()在Firefox中使用SSL客户端身份验证失败
- NodeJS Passport身份验证-始终重定向到失败url
- Express.js Passport身份验证自动失败跳过策略
- Firebase电子邮件身份验证网络请求失败
- $http拦截器:身份验证失败时重定向
- ruby on rails-请求javascript规范失败,设计身份验证
- 使用node、passport和react进行Github身份验证失败