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 9238923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:52:18+00:00 2026-06-18T07:52:18+00:00

How do I test if the response of a controller action in Rails is

  • 0

How do I test if the response of a controller action in Rails is a file? (rack-test or capybara)

Should I use unit tests to do it?

The scenario is simple: I have to test if the exported users from the database are the same contained in the generated .csv from an action.

  • 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-18T07:52:19+00:00Added an answer on June 18, 2026 at 7:52 am

    You don’t need rack-test or Capybara to do this. The default test infrastructure is all you need. Simply check that the Content-Type is CSV:

    test "returns a CSV file" do
      get :index, format: :csv
      assert_response :success
      assert_equal "text/csv", response.content_type
    end
    

    If you want to take it one step further, you can parse the returned CSV to make sure it is valid and test the values returned:

    test "returns a valid CSV file and data" do
      get :index, format: :csv
      assert_response :success
      assert_equal "text/csv", response.content_type
    
      csv = CSV.parse response.body # Let raise if invalid CSV
      assert csv
      assert_equal 6, csv.size
      assert_equal "Joe Smith", csv[3][4]
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Controller Action I set Cookie with Response.SetCookie(myCookie) method. In my Unit Test
I am trying to use factory girl to test my create action in rails.
Let's say I have a simple action in my controller that ends with: render(contentType:
i am new to rails testing and i am using unit:test. I have an
I am running on Castle's trunk, and trying to unit-test a controller-action where validation
I have a controller action that should only respond to AJAX calls: def archive
When testing a JSON response from an RSPEC controller test using DHH's JBuilder, my
I want to create a simple access unit test like it is shown in
Sitting here with a simple rails 3 app in which I have a simple
I'd like to test if my Rails controller sets a valid options (in this

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.