简体   繁体   English

没有html.erb时进行黄瓜测试js.erb函数

[英]Cucumber Testing js.erb functions when no html.erb exists

My rails application is using js.erb views instead of html.erb views for specific windows. 我的Rails应用程序在特定窗口中使用js.erb视图而不是html.erb视图。 This works fine in practice, but when I'm using cucumber tests with capybara it gives me an error of 这在实践中效果很好,但是当我将黄瓜测试与水豚一起使用时,它给我一个错误

Missing template admin/groups with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml],    :formats=>[:html], :locale=>[:en, :en]} in view paths

When I click the button pertaining to this particular view. 当我单击与该特定视图有关的按钮时。 There is no groups.html.erb but there is a groups.js.erb. 没有groups.html.erb,但是有一个groups.js.erb。 I want to somehow tell cucumber/capybara to not try to render the groups.html.erb but still render the groups.js.erb. 我想以某种方式告诉Cucumber / Capybara不要尝试渲染groups.html.erb,而是仍然渲染groups.js.erb。 I would prefer not to generate an unnecessary html file to render the same thing the escape javascript below is doing. 我希望不要生成不必要的html文件来呈现下面的转义javascript正在执行的相同操作。

groups.js.erb: groups.js.erb:

$("#admin_content").html("<%= escape_javascript(render :partial => 'groups') %>");

Relevant admin controller method: 相关管理控制器方法:

def groups
    @groups = Group.all
end

You should use proper MIME type handling for your responses. 您应该对响应使用正确的MIME类型处理。 Try this: 尝试这个:

def groups
  @groups = Group.all
  respond_to do |format|
    format.js
  end
end

eventually you can be more specific about how to respond : 最终,您可以更具体地了解如何响应:

format.js { render layout: false }

more info on respond_to here . 有关response_to的更多信息,请点击此处

note: if your controller only manages js responses, you can add respond_to :js at the top of the class, and then use respond_with @object in your actions. 注意:如果您的控制器仅管理js响应,则可以在类的顶部添加response_to respond_to :js ,然后在操作中使用respond_with @object

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM