gpt4 book ai didi

ruby-on-rails - RSpec 测试被分页破坏(Kaminari)

转载 作者:行者123 更新时间:2023-12-03 11:05:24 25 4
gpt4 key购买 nike

我有一个正在通过的 View 规范,但现在已将分页(通过 Kaminari gem)添加到 View 中。我仍在尝试了解 RSpec 的语法……因此,当页面在浏览器中正常工作时,请寻求帮助以使其通过。我知道很多人不赞成查看规范的脆弱性(可能是出于这样的原因),但我仍然希望让这个通过

我正在将一些 stub 帖子分配给 @posts 数组。但是数组不响应 current_page .那么我应该如何在 RSpec 中处理这个问题?

Failures:

1) posts/index.html.haml renders a list of posts
Failure/Error: render
ActionView::Template::Error:
undefined method `current_page' for #<Array:0x000001028ab4e0>
# ./app/views/posts/index.html.haml:31:in `_app_views_posts_index_html_haml__291454070937541541_2193463480'
# ./spec/views/posts/index.html.haml_spec.rb:39:in `block (2 levels) in <top (required)>'
spec/views/posts/index.html.haml_spec.rb :
require 'spec_helper'

describe "posts/index.html.haml" do
before(:each) do
...
assign(:posts, [
Factory.stub(:post),
Factory.stub(:post)
])
view.should_receive(:date_as_string).twice.and_return("June 17, 2011")
...
end

it "renders a list of posts" do
render
rendered.should have_content("June 17, 2011")
...
end
end

最佳答案

您还可以执行以下操作:

assign(:posts, Kaminari.paginate_array([
Factory.stub(:post),
Factory.stub(:post)
]).page(1))

关于ruby-on-rails - RSpec 测试被分页破坏(Kaminari),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7080335/

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