我有一个UsersController,它有index和new操作。我使用haml,索引haml文件包含以下代码:
= link_to 'Add User', new_user_path, { :remote => true, 'data-toggle' => 'modal',
'data-target' => '#modal-window', 'class' => 'btn btn-primary pull-right' }因此,当用户单击“Add user”时,_new.html.haml部分将作为一个模式呈现给用户。效果很好。下面是控制器中的新操作:
def new
@user = User.new
respond_to do |format|
format.html
format.js
end
end现在,在我的控制器规范中,我试图做以下工作:
describe "new action" do
before do
get 'new'
end
# specs for 'new' action go here
end但是,这会导致错误。
Failure/Error: get 'new'
ActionView::MissingTemplate:
Missing template users/new, application/new with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :haml]}. Searched in:
* "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x007faa44b03218>"大概是因为它找不到new.html.haml,当然因为文件是一个名为_new.html.haml的部分文件而不存在。get处理部分的正确语法是什么?如果没有,我如何测试new操作?
发布于 2013-09-28 17:23:37
好吧,我在新动作中做了些改变,让它发挥作用:
respond_to do |format|
format.html { render :partial => 'new' }
format.js
end当应用程序运行rails时,rails会显示出部分内容,但我想rspec应该是明确的。如果有更好的方法做这件事,我会很高兴听到他们。
https://stackoverflow.com/questions/19069040
复制相似问题