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

  • SEARCH
  • Home
  • 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 8545499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:48:18+00:00 2026-06-11T12:48:18+00:00

In a Rails 3.2.8 controller test, I’d like to use an assert_select to control

  • 0

In a Rails 3.2.8 controller test, I’d like to use an assert_select to control the content an unescaped field rendered in my view using the raw or the #html_safe method :

<div id="summary">
    <%= raw @doc.summary %>
</div>

But in my test, both these assertions fail :

# Fixture loading in doc variable, get :show, assert_response ...
assert_select('#summary', doc.summary)
assert_select('#summary', doc.summary.html_safe)

If my summary is something like <p>Stuff:</p><ul><li>Stuff1</li><li>Stuff1</li></ul>, then the test tells me, for both lines, that :

<"<p>Stuff:</p><ul><li>Stuff1</li><li>Stuff2</li></ul>">
expected but was
<"Stuff:\n  \n    Stuff1\n    Stuff2">

When in test mode, it seems to render the view with \n instead of HTML tags, as if escaping for a CLI display.

But when I launch the server and display my page in the browser, this part is rendered with HTML tags and no \n.

Is it a bug in the controller test rendering engine ? Do you know how to avoid it ?

  • 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-11T12:48:20+00:00Added an answer on June 11, 2026 at 12:48 pm

    Found the solution :

    assert_select('#summary', :html => doc.summary)
    

    This way, whatever transformation applied to the DOM-selected content is also applied to the second arg before comparison.


    NB: Beware of the way you write your fixtures though.

    The following syntax:

    doc:
      summary: |
        <p>Stuff:</p><ul><li>Stuff1</li><li>Stuff2</li></ul>
    

    gets a final extra \n from the assert_select, compared to :

    doc:
      summary: <p>Stuff:</p><ul><li>Stuff1</li><li>Stuff2</li></ul>
    

    I have no idea why this occurs, but it makes the assert fail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using RSpec + Shoulda to test my RESTful controller in Rails 3. I'm
I'm using rspec-rails, version 1.2.6. In a controller test describe WebsController do ... I
I'd like to write a Rails functional test for a non-RESTful route. I'm using
I have a Rails controller action to test. In that action, a method User.can?
I'm new to rails and I'm trying to test a controller with rspec. My
In my Rails controller I have something like: def authenticate_user! if not current_user #
Within the scope of a Rails controller or a view: How can I query
I have this command in a Rails controller open(source) { |s| content = s.read
i would like to create a Rails controller that download a serie of jpg
In our rspec test for rails 3.1.0 app, we use both Factory.build and Factory.attributes_for.

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.