Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8953765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:10:18+00:00 2026-06-15T14:10:18+00:00

I’m running a test that I’ve created in rails using a simple assert_select that

  • 0

I’m running a test that I’ve created in rails using a simple assert_select that should populate 5 divs based on my fixtures. But every time it’s failing saying 0 elements were found, when 5 were expected. Is it possible to see the output that the test is basing this on?

Below is the specific test that’s giving me trouble:

require 'test_helper'

class PostsControllerTest < ActionController::TestCase
  test "should get index" do
    get :index
    assert_response :success
    assert_select '.contentBox', minimum: 5
  end
end

and the error:

Finished tests in 0.403847s, 2.4762 tests/s, 4.9524 assertions/s.

  1) Failure:
test_should_get_index(PostsControllerTest) [/var/www/site/test/functional/posts_controller_test.rb:7]:
Expected at least 5 elements matching ".contentBox", found 0.

1 tests, 2 assertions, 1 failures, 0 errors, 0 skips
rake aborted!

It should be noted that when manually adding everything from rails console (e.g. Post.new, etc) everything works fine and I can manually check the source and see that there are the appropriate number of items. So it leads me to believe that I’ve done something wrong with the test.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:10:20+00:00Added an answer on June 15, 2026 at 2:10 pm

    You should be able to use puts @response.body to print the body of the page that is returned if you want to inspect it. You could also consider using Capybara which if you did you could use put page.body

    What you will have to add to the test is creating 5 posts. So doing something like:

    class PostsControllerTest < ActionController::TestCase
      test "should get index" do
        get :index
        puts @response.body #This should print what is returned from get:index
        assert_response :success
        assert_select '.contentBox', minimum: 5
      end
    end
    

    Update for question in comments:
    If you have in your controller:
    @posts = Post.all

    Then in your view you should have something like:

    <% @post.all do |post| %>
      <div class="contentBox">
        Title: <%= post.title %> 
      </div>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.