gpt4 book ai didi

ruby-on-rails - RSPec 和 Rails 3 的 Mising 模板错误

转载 作者:行者123 更新时间:2023-11-28 20:01:29 24 4
gpt4 key购买 nike

迁移到 Rails 3 后,一些 RSpec 测试失败了

例子:

Controller :

class ProfilesController < ApplicationController
def create
@profile = Profile.new(params[:note])
respond_to do |format|
if @profile.save
format.html { redirect_to :back }
else
format.html { render :new }
format.js do
render(:update) do |page|
page.flash.show @profile.errors.full_messages.join(', ')
end
end
end
end
end
end

规范:

require 'spec_helper'

describe ProfilesController do
before(:each) { sign_in mock_model(Account).as_null_object }

context 'POST create' do
it 'is accessible for logged in user' do
controller.should_receive(:create)
post :create
end
end

end

失败:

  19) ProfilesController POST create is accessible for logged in user
Failure/Error: post :create
ActionView::MissingTemplate:
Missing template profiles/create with {:locale=>[:en, :en], :formats=>[:html], :handlers=>[:rjs, :rhtml, :rxml, :builder, :erb]} in view paths "#<RSpec::Rails::ViewRendering::EmptyTemplatePathSetDecorator:0x1059d48f0>"
# ./spec/controllers/profiles_controller_spec.rb:48

最佳答案

你能展示你的 Controller 代码吗?可能是您真的没有在 profiles_controller#create 中执行任何重定向操作。

像这样:

def create
...
redirect_to '/'
end

关于ruby-on-rails - RSPec 和 Rails 3 的 Mising 模板错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6266619/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com