我有一个视图规范(View Spec),它以前是通过的,但现在已经破了,原因是在视图中添加了分页(Kaminari gem)。我还在尝试弄清楚 RSpec 的语法...所以希望得到帮助,使其通过测试,因为在浏览器中页面可以正常工作。我知道很多人不喜欢视图规范(View Spec)因为它们很脆弱(可能是出于这样的原因),但我仍然希望保持这个规范通过测试
我将一些存根(post)赋值给 @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
current_page
?!? 我只知道这个规范曾经失败,因为帖子数组没有响应它...但是,你是对的,这似乎很奇怪? 我会把这个问题保持开放状态一段时间,看看是否有更好的答案出现。 - Meltemi