Forum: Ruby on Rails assert_select trying to verify the presence of a textarea

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Gian (Guest)
on 2007-06-22 12:33
(Received via mailing list)

One of my functional tests looks like this:

  def test_presence_of_free_text
    profile = Profile.find :first
    post :edit, {:id =>}
    assert_select "textarea", :name => "record[free_text_ec]"

The test results in a failure, because the element cannot be found.

I'm pretty sure the element should be there, and I've tried the
combinations as well:
assert_select "textarea", :name => "record[free_text_ec]"
assert_select "textarea.record_free_text_ec", :name =>
assert_select "input[type=textarea][id=record_free_text_ec]"
assert_select "[type=textarea][id=record_free_text_ec]"
assert_select "input[type=TEXTAREA][id=record_free_text_ec]"
assert_select "LI textarea", :name => "record[free_text_ec]"
"html:root>body>div>div>div>div>form>ol>li>ol>li>textarea", :id =>

They all fail.

One does not fail, and that's
assert_select "*", :name => "record[free_text_ec]"
But, to be sure, I've checked this option with a dummy name
(e.g. assert_select "*", :name => "Hjdueubduagagaxxxxx")
and it strangely enough it succeeds as well.

Does anyone know how to make the assert_select find my textarea tag


Daniel -. (Guest)
on 2007-06-22 12:42
(Received via mailing list)
On 6/22/07, Gian <removed_email_address@domain.invalid> wrote:
>   end
I believe that the selector "record[free_text_ec]" Is not correct.  It's
looking for a tag called record with a free_text_ec attribute.

I don't believe your call is doing what you expect though.  The :name
is going towards an equality? argument, not the selector argument.

I believe you test should read

assert_select "textarea#record[id=free_text_ec]"

Gian (Guest)
on 2007-06-22 13:22
(Received via mailing list)
Thanks for your reply Daniel.

I'm afraid this does not work either.

An hml snippet of the actual page looks like this:
  <li class="form-element ">
    <label for="record_free_text_ec">Additional text for the EC</
    <div class="info">&nbsp;</div>
    <textarea cols="40" id="record_free_text_ec"
name="record[free_text_ec]" rows="20">

I can't see what's wrong in the assert_select


Daniel -. (Guest)
on 2007-06-22 13:29
(Received via mailing list)
On 6/22/07, Gian <removed_email_address@domain.invalid> wrote:
> label>
> Gian

Ok that makes it clear.  The id is id="record_free_text_ec"  so the
assert_select should be

assert_select "textarea#record_free_text_ec"

That should find it. The # will find a textarea tag with the given id.
is pretty much the same as a css selector.

Gian (Guest)
on 2007-06-22 15:22
(Received via mailing list)
again thanks Daniel,

In my case the assert_select works for pages that are NOT using
active scaffold, I just do, as you proposed...

assert_select "textarea#record_free_text_ec"

and this works.

I think the problem lies in the fact my (GET) request in the
test, is probably not returning what I expected, and that's why the
assert_select doesn't find the textarea.

>From the browser the GET returns the right html, from the
test the GET is giving me values 0 or 302 for an assert_response.

I've checked the response with puts @response.inspect, and it
doesn't look like what I should get.

Pretty weird, maybe I'm overlooking something...


Gian (Guest)
on 2007-06-26 15:05
(Received via mailing list)
Just for the records, for whoever might end up on this thread.

I found out what the problem was, it has nothing to do with active

The cause of this problem was a missing fixture in my tests.

More specifically. I use the plug in act_as_authenticated, and
the first line in my tests is usually login_as(:someone), that
sets the user as logged in.

The method login_as worked fine, and the @current_user instance
variable was set in my controllers, but the instances of an
(i.e. has_and_belongs_to_many :roles) where not made and not set
in the specific user instance, this caused some conditions to fail and
resulted in a redirect.

Moral of the story: I needed to add an extra fixture to my functional
This topic is locked and can not be replied to.