Rspec/TDD 初学者。我有一个失败的规范,我不知道为什么。一切都在浏览器中正常运行。我正在使用 Kaminari 进行分页,默认为每页 25 个项目。
规格:
describe "Question Pages" do
subject { page }
describe "index page" do
before { visit questions_path }
before { 25.times { FactoryGirl.create(:question) } }
after { Question.delete_all }
it { should have_selector('h1', 'All Questions') }
it "should list the questions" do
Question.page(1).each do |question|
page.should have_link(question.title, href: question_path(question))
end
end
end
end
失败:
1) Question Pages index page should list the questions
Failure/Error: page.should have_link(question.title, href: question_path(question))
Capybara::ExpectationNotMet:
expected to find link "Lorem Ipsum 33" but there were no matches
# ./spec/features/question_pages_spec.rb:17:in `block (4 levels) in <top (required)>'
# ./spec/features/question_pages_spec.rb:16:in `block (3 levels) in <top (required)>'
当我告诉它制作 25 时,为什么它在第 33 项上失败?
工厂:
FactoryGirl.define do
factory :question do
sequence(:title) { |i| "Lorem Ipsum #{i}" }
body "Dolor sit amet"
passed false
end
end
看法:
<h1>All Questions</h1>
<%= paginate @questions %>
<ul class="questions">
<% @questions.each do |question| %>
<li>
<section class="question_<%= question.id %> clearfix">
<h2><%= link_to truncate(question.title, length: 62), question_path(question) %></h2>
<p><%= truncate(question.body, length: 70) %></p>
</li>
<% end %>
</ul>
控制器:
class QuestionsController < ApplicationController
def index
@questions = Question.page(params[:page])
end
end
ruby 1.9.3p429,rails 3.2.13,rspec-rails 2.13.1,capybara 2.1.0,kaminari 0.14.1,faker 1.0.1,factory_girl_rails 4.1.0