Ruby on rails 按钮规格不合格
因此,我最近承担了一个项目,将Ruby 1.9.3/Rails 3.2应用程序升级到Ruby 2/Rails 4.0.2。一切似乎都很好,但我有一个失败的规范。我正在尝试测试页面底部的“建议”框按钮是否正常工作 故障信息为:Ruby on rails 按钮规格不合格,ruby-on-rails,ruby,ajax,testing,rspec,Ruby On Rails,Ruby,Ajax,Testing,Rspec,因此,我最近承担了一个项目,将Ruby 1.9.3/Rails 3.2应用程序升级到Ruby 2/Rails 4.0.2。一切似乎都很好,但我有一个失败的规范。我正在尝试测试页面底部的“建议”框按钮是否正常工作 故障信息为: Failures: 1) StaticPages Scheduler Page after authenticating filling in the suggestion form after submitting the form should send an ema
Failures:
1) StaticPages Scheduler Page after authenticating filling in the suggestion form after submitting the form should send an email request with the form contents
Failure/Error: click_button("suggestion-button")
ActionController::UnknownFormat:
ActionController::UnknownFormat
# ./app/controllers/static_pages_controller.rb:39:in `suggestion'
# ./spec/features/static_pages_spec.rb:93:in `block (6 levels) in <top (required)>'
控制器显示:
def suggestion
if user_signed_in?
user = current_user.email
else
user = "< not logged in >"
end
if params[:suggestion]
ContactMailer.suggestion_email(params[:suggestion], params[:pathname], user).deliver!
end
respond_to do |format|
format.json { render json: params[:suggestion] }
end
end
def建议
如果用户已登录?
user=current_user.email
其他的
user=“<未登录>”
终止
如果参数[:建议]
ContactMailer.suggestion\u电子邮件(参数[:suggestion],参数[:路径名],用户)。发送!
终止
回应待办事项|格式|
format.json{render json:params[:suggestion]}
终止
终止
页面上按钮的来源是:
<button type="submit" class="btn" id="suggestion-button">
Tell Us!
</button>
</form>
告诉我们!
//提交表单后,灰显并禁用表单
$(文档).ready(函数(){
$(“#页脚建议表单”).bind(“ajax:complete”,函数(事件、xhr、状态){
log($(“#页脚建议表单输入”);
$(“#页脚建议表单输入”).attr(“禁用”、“禁用”);
$(“#页脚建议表单按钮”).attr(“禁用”、“禁用”).html(“谢谢”);
log(“做到了!”);
});
$(“#建议路径名”).val(location.pathname);
});
是因为它是AJAX表单吗?或者只是一个在Rails 3.2中有效但在Rails 4中由于某些更改而不再有效的测试?我感谢任何帮助,我真的迷路了
我确实尝试在规范中使用:js=>true并下载了capybara webkit gem,但当我尝试运行规范时,它会进行测试,然后挂在那里等待一些从未发生过的事情
编辑:进度。现在它进入了测试,坐了一个大的,然后失败了
1) 验证后的StaticPages计划程序页面提交表单后填写建议表单应发送包含表单内容的电子邮件请求
失败/错误:在{visit scheduler_path}之前
运行时错误:
机架应用程序在引导期间超时
/spec/features/static_pages_spec.rb:31:in`block(3层)in能否突出显示
static_pages_controller.rb中的行号:39
?39:respond_to do | format |听起来ajax请求没有正确执行。我想让你们看一篇关于自己调试这些问题的文章,这里是控制器和规范文件的要点:这仍然没有解决。我通过为capybara和database_cleaner安装webkit JS驱动程序取得了进展。现在它进行了测试,似乎挂起了一段时间,然后由于运行时错误而失败:机架应用程序在引导期间超时
<button type="submit" class="btn" id="suggestion-button">
Tell Us!
</button>
</form>
<script>
// After form submission, gray out and disable the form
$(document).ready(function(){
$("#footer-suggestion-form").bind("ajax:complete", function(event, xhr, status){
console.log($("#footer-suggestion-form input"));
$("#footer-suggestion-form input").attr("disabled","disabled");
$("#footer-suggestion-form button").attr("disabled","disabled").html("Thanks!");
console.log("did it!");
});
$("#suggestion-pathname").val(location.pathname);
});
</script>