ruby on rails 3 - Rspec test describing listing items on index failing -


rspec/tdd beginner. have spec failing , don't know why. works in browser should. using kaminari pagination, defaults 25 items per page.

spec:

describe "question pages"      subject { page }      describe "index page"          before { visit questions_path }         before { 25.times { factorygirl.create(:question) } }         after { question.delete_all }         { should have_selector('h1', 'all questions') }          "should list questions"             question.page(1).each |question|                 page.should have_link(question.title, href: question_path(question))             end         end     end end 

failure:

 1) question pages index page should list questions      failure/error: page.should have_link(question.title, href: question_path(question))      capybara::expectationnotmet:        expected find link "lorem ipsum 33" there 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)>' 

why failing on item number 33 when told make 25?

factory:

factorygirl.define      factory :question         sequence(:title) { |i| "lorem ipsum #{i}" }         body "dolor sit amet"         passed false     end end 

view:

<h1>all questions</h1>  <%= paginate @questions %>  <ul class="questions">      <% @questions.each |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> 

controller:

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

can ensure creating factories before visit ?

maybe instead of

before { visit questions_path } before { 25.times { factorygirl.create(:question) } } 

that

before    25.times { factorygirl.create(:question) }   visit questions_path  end 

if not maybe can display content of page?

puts page.inspect 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -