Hello, One of my functional tests looks like this: def test_presence_of_free_text profile = Profile.find :first post :edit, {:id => profile.id} assert_select "textarea", :name => "record[free_text_ec]" end 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 following combinations as well: assert_select "textarea", :name => "record[free_text_ec]" assert_select "textarea.record_free_text_ec", :name => "record[free_text_ec]" 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]" assert_select "html:root>body>div>div>div>div>form>ol>li>ol>li>textarea", :id => "record_free_text_ec" 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 correctly? Thanks, Gian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel N
2007-Jun-22 08:41 UTC
Re: assert_select trying to verify the presence of a textarea
On 6/22/07, Gian <gian.franco.casula-aZ+A4iwyWieEVqv0pETR8A@public.gmane.org> wrote:> > > Hello, > > One of my functional tests looks like this: > > def test_presence_of_free_text > profile = Profile.find :first > post :edit, {:id => profile.id} > assert_select "textarea", :name => "record[free_text_ec]" > endI 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 option is going towards an equality? argument, not the selector argument. I believe you test should read assert_select "textarea#record[id=free_text_ec]" HTH Daniel --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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</ label> <div class="info"> </div> <textarea cols="40" id="record_free_text_ec" name="record[free_text_ec]" rows="20"> </textarea> </li> ... I can''t see what''s wrong in the assert_select Cheers, Gian On 22 jun, 10:41, "Daniel N" <has....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 6/22/07, Gian <gian.franco.cas...-aZ+A4iwyWieEVqv0pETR8A@public.gmane.org> wrote: > > > > > Hello, > > > One of my functional tests looks like this: > > > def test_presence_of_free_text > > profile = Profile.find :first > > post :edit, {:id => profile.id} > > assert_select "textarea", :name => "record[free_text_ec]" > > 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 option > is going towards an equality? argument, not the selector argument. > > I believe you test should read > > assert_select "textarea#record[id=free_text_ec]" > > HTH > Daniel--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel N
2007-Jun-22 09:28 UTC
Re: assert_select trying to verify the presence of a textarea
On 6/22/07, Gian <gian.franco.casula-aZ+A4iwyWieEVqv0pETR8A@public.gmane.org> wrote:> > > 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</ > label> > <div class="info"> </div> > <textarea cols="40" id="record_free_text_ec" > name="record[free_text_ec]" rows="20"> > </textarea> > </li> > ... > > I can''t see what''s wrong in the assert_select > > Cheers, > > GianOk 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. This is pretty much the same as a css selector. HTH Daniel --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 thetest 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... Cheers, Gian On 22 jun, 11:28, "Daniel N" <has....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 6/22/07, Gian <gian.franco.cas...-aZ+A4iwyWieEVqv0pETR8A@public.gmane.org> wrote: > > > > > > > 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</ > > label> > > <div class="info"> </div> > > <textarea cols="40" id="record_free_text_ec" > > name="record[free_text_ec]" rows="20"> > > </textarea> > > </li> > > ... > > > I can''t see what''s wrong in the assert_select > > > Cheers, > > > 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. This > is pretty much the same as a css selector. > > HTH > Daniel--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 scaffold. 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 association (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 test. On 22 jun, 13:21, Gian <gian.franco.cas...-aZ+A4iwyWieEVqv0pETR8A@public.gmane.org> wrote:> again thanks Daniel, > > In my case the assert_select works for pages that are NOT usingactivescaffold, 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... > > Cheers, > > Gian > > On 22 jun, 11:28, "Daniel N" <has....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On 6/22/07, Gian <gian.franco.cas...-aZ+A4iwyWieEVqv0pETR8A@public.gmane.org> wrote: > > > > 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</ > > > label> > > > <div class="info"> </div> > > > <textarea cols="40" id="record_free_text_ec" > > > name="record[free_text_ec]" rows="20"> > > > </textarea> > > > </li> > > > ... > > > > I can''t see what''s wrong in the assert_select > > > > Cheers, > > > > 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. This > > is pretty much the same as a css selector. > > > HTH > > Daniel--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---