2013-02-14 105 views
0

我想在需要身份验证(通过设计)的Web应用程序上测试一个操作。具体的操作使用JavaScript,因此我申请了js选项来规范这样:请求规格为JavaScript失败,设计身份验证

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)此功能规格的顶部,我验证文件中使用

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 

我在网上搜索,发现只有回应说,不要在我的叫responseaction控制器动作。放心,我没有这样的行为;只有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"[email protected][0..-5]+"-"[email protected][-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,并且我确实需要一种方式来在登录时测试这些操作。

回答

0

在没有首先测试操作已完成的情况下,要小心检查非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) 

水豚声称自己是非常聪明的等待页面元素是可见的 - 情况因人而异。

如果您的应用需要登录,您的请求规范应使用正常的登录过程 - 访问登录页面,输入凭据,然后导航到要测试的页面。