隔离模式和渲染下的控制器规格:更新

发布于 2024-08-11 15:24:35 字数 656 浏览 2 评论 0原文

我正在使用 RSpec 来编写我的控制器测试/规格。

我遇到的问题是呈现以下代码:

render :update do |page|
  page['middle_content'].replace_html :partial => "admin/pages/show"
end

隔离模式是默认模式,不是吗?

我该如何解决这个问题或者我做错了什么?

例如,这里是一个失败的控制器规范:

it "should be succesful" do
  xhr :delete, :destroy, :page_id => 1, :id => 1
  response.should be_success
end

错误消息:

should be succesful
Mock 'Page_1' received unexpected message :title with (no args)
On line #1 of app/views/admin/pages/_administration.html.erb

管理部分在显示部分中呈现

最好的问候

编辑:我已将此问题发布到 RSpec 的灯塔帐户。

I am using RSpec for writing my controller tests/specs.

I faced the problem, that the following code gets rendered:

render :update do |page|
  page['middle_content'].replace_html :partial => "admin/pages/show"
end

Isolation mode is the default, isn't it?

How can I fix this or am I doing something wrong?

Here is for example a failing controller spec:

it "should be succesful" do
  xhr :delete, :destroy, :page_id => 1, :id => 1
  response.should be_success
end

The error message:

should be succesful
Mock 'Page_1' received unexpected message :title with (no args)
On line #1 of app/views/admin/pages/_administration.html.erb

The adminitration partial gets rendered in the show partial

Best regards

EDIT: I have posted this issue to the lighthouse account of RSpec.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

李白 2024-08-18 15:24:35

也许这会对你有帮助。如果我添加以下内容,

controller.stub!(:render).and_return(nil)

一切都会正常(视图不会被渲染)。

你们有人有想法吗?

Maybe this will help you. If I add the following

controller.stub!(:render).and_return(nil)

everything will work(the views won't get rendered).

Does anybody of you got an idea?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文