Hi, I have two select lists in my app called ''topic'' and ''member''. Based on what I select in topic, member is populated accordingly (using java script). eg. If I select ''subject1'' in topic, member should be populated with the values ''prof x'', ''prof y'' and ''prof z''. Can I test that my java script function is populating member with the correct values in a unit test? So far I have tried: def test_correct_value_returned applicant = Applicant.new(valid_attributes(:topic => "", :member => "",)) applicant.topic = "subject1" assert_equal ["prof x", "prof y", "prof z"], applicant.member end But I get: 1) Failure: test_test_correct_value_returned(ApplicantTest) [/test/unit/applicant_test.rb:2098]: <["prof x", "prof y", "prof z"]> expected but was <"">. Can anyone give me a pointer as to how I could go about getting this to work? Thanks very much. -- Posted via http://www.ruby-forum.com/.
On Jul 12, 8:02 pm, Jim Burgess <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > > I have two select lists in my app called ''topic'' and ''member''. > Based on what I select in topic, member is populated accordingly (using > java script). > eg. If I select ''subject1'' in topic, member should be populated with the > values ''prof x'', ''prof y'' and ''prof z''. > Can I test that my java script function is populating member with the > correct values in a unit test? >Not really, since your ruby code doesn''t know how to execute javascript. (I often use the Test.Unit stuff from prototype to write javascript unit tests) Fred> So far I have tried: > > def test_correct_value_returned > applicant = Applicant.new(valid_attributes(:topic => "", :member => > "",)) > applicant.topic = "subject1" > assert_equal ["prof x", "prof y", "prof z"], applicant.member > end > > But I get: > 1) Failure: > test_test_correct_value_returned(ApplicantTest) > [/test/unit/applicant_test.rb:2098]: > <["prof x", "prof y", "prof z"]> expected but was > <"">. > > Can anyone give me a pointer as to how I could go about getting this to > work? > Thanks very much. > -- > Posted viahttp://www.ruby-forum.com/.
> Not really, since your ruby code doesn''t know how to execute > javascript. (I often use the Test.Unit stuff from prototype to write > javascript unit tests)Thanks for that Fred. It''s good to know that I was barking up the wrong tree. Since reading your post I have been looking at the javascript_test plugin but still unsure as to how to write a sensible test with it. I guess I''ll rephrase my question and post it again. -- Posted via http://www.ruby-forum.com/.