I''m writing specs for an XHR, and am having troubles getting my specs to see that a <div> is being hidden. === map_filter.rjs 19 else 20 puts "map_filter.rjs> else!" 21 # Display the filter errors. 22 page[''map-filter-errors''].hide 23 page[''map-filter-errors''].replace_html @map_filter_errors.join 24 page[''map-filter-errors''].visual_effect :blind_down 25 end When the spec runs, line 20 above spits out "...else!" on the CLI, so I know that the RJS file is being processed. === neighbourhoods_controller_spec.rb 428 describe ''with views integrated'' do 429 integrate_views 430 431 it ''should hide the map filter errors <div>'' do 432 do_xhr @xhr_params 433 response.should have_rjs 434 # response.should have_rjs(:hide, ''map-filter-errors'') 435 end 436 end Why might line 433 above fail?: ==$ script/spec -e ''should hide the map filter errors <div>'' spec/ controllers/neighbourhoods_controller_spec.rb map_filter.rjs> else! F 1) ''NeighbourhoodsController handling POST /neighbourhoods/map_filter if a filter error occured with views integrated should hide the map filter errors <div>'' FAILED No RJS statement that replaces or inserts HTML content. ./spec/controllers/neighbourhoods_controller_spec.rb:433: script/spec:4: Finished in 0.489336 seconds 1 example, 1 failure == Any hints? -Nick
On 2008-09-28, at 17:20, Nick Hoffman wrote:> 431 it ''should hide the map filter errors <div>'' do > 432 do_xhr @xhr_params > 433 response.should have_rjs > 434 # response.should have_rjs(:hide, ''map-filter-errors'') > 435 endI just discovered that I need to pass :chained_replace_html to #have_rjs , like so: response.should have_rjs(:chained_replace_html, :hide, ''map-filter- errors'') However, after googling around and looking through the source for #assert_select_rjs , I have no idea what :chained_replace_html does, nor why :hide is insufficient. Would someone mind enlightening me? Thanks! -Nick
On Sun, Sep 28, 2008 at 10:59 PM, Nick Hoffman <nick at deadorange.com> wrote:> On 2008-09-28, at 17:20, Nick Hoffman wrote: >> >> 431 it ''should hide the map filter errors <div>'' do >> 432 do_xhr @xhr_params >> 433 response.should have_rjs >> 434 # response.should have_rjs(:hide, ''map-filter-errors'') >> 435 end > > I just discovered that I need to pass :chained_replace_html to #have_rjs , > like so: > response.should have_rjs(:chained_replace_html, :hide, ''map-filter-errors'') > > However, after googling around and looking through the source for > #assert_select_rjs , I have no idea what :chained_replace_html does, nor why > :hide is insufficient. Would someone mind enlightening me?I''m not sure why that is offhand, still waking up this fine Monday morning, but I''d recommend throwing this question to the rails mailing list if nobody responds here. Cheers, David> > Thanks! > -Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On 2008-09-29, at 07:58, David Chelimsky wrote:> On Sun, Sep 28, 2008 at 10:59 PM, Nick Hoffman <nick at deadorange.com> > wrote: >> On 2008-09-28, at 17:20, Nick Hoffman wrote: >>> >>> 431 it ''should hide the map filter errors <div>'' do >>> 432 do_xhr @xhr_params >>> 433 response.should have_rjs >>> 434 # response.should have_rjs(:hide, ''map-filter-errors'') >>> 435 end >> >> I just discovered that I need to pass :chained_replace_html to >> #have_rjs , >> like so: >> response.should have_rjs(:chained_replace_html, :hide, ''map-filter- >> errors'') >> >> However, after googling around and looking through the source for >> #assert_select_rjs , I have no idea what :chained_replace_html >> does, nor why >> :hide is insufficient. Would someone mind enlightening me? > > I''m not sure why that is offhand, still waking up this fine Monday > morning, but I''d recommend throwing this question to the rails mailing > list if nobody responds here. > > Cheers, > DavidHi David. I''ve taken your advice and posted to the ror-talk list: http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/f7fc3f63660a7f33 I''m not sure what you meant by "why that is offhand"... Cheers, Nick
On Mon, Sep 29, 2008 at 10:51 AM, Nick Hoffman <nick at deadorange.com> wrote:> On 2008-09-29, at 07:58, David Chelimsky wrote: >> >> On Sun, Sep 28, 2008 at 10:59 PM, Nick Hoffman <nick at deadorange.com> >> wrote: >>> >>> On 2008-09-28, at 17:20, Nick Hoffman wrote: >>>> >>>> 431 it ''should hide the map filter errors <div>'' do >>>> 432 do_xhr @xhr_params >>>> 433 response.should have_rjs >>>> 434 # response.should have_rjs(:hide, ''map-filter-errors'') >>>> 435 end >>> >>> I just discovered that I need to pass :chained_replace_html to #have_rjs >>> , >>> like so: >>> response.should have_rjs(:chained_replace_html, :hide, >>> ''map-filter-errors'') >>> >>> However, after googling around and looking through the source for >>> #assert_select_rjs , I have no idea what :chained_replace_html does, nor >>> why >>> :hide is insufficient. Would someone mind enlightening me? >> >> I''m not sure why that is offhand, still waking up this fine Monday >> morning, but I''d recommend throwing this question to the rails mailing >> list if nobody responds here. >> >> Cheers, >> David > > Hi David. I''ve taken your advice and posted to the ror-talk list: > http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/f7fc3f63660a7f33 > > I''m not sure what you meant by "why that is offhand"...That''s a common US expression meaning "without looking into it" or "off the top of my head". :)> > Cheers, > Nick > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Mon, 29 Sep 2008 11:34:34 -0500, you wrote:>On Mon, Sep 29, 2008 at 10:51 AM, Nick Hoffman <nick at deadorange.com> wrote: >> On 2008-09-29, at 07:58, David Chelimsky wrote: >>>...>>> >>> I''m not sure why that is offhand, still waking up this fine Monday >>> morning, but I''d recommend throwing this question to the rails mailing >>> list if nobody responds here. >>> >>> Cheers, >>> David >>...>> >> I''m not sure what you meant by "why that is offhand"... > >That''s a common US expression meaning "without looking into it" or >"off the top of my head".I think it''s a parsing problem, rather than an idiom problem. I think he read it as if "offhand" were the object of "that is offhand," which doesn''t make much sense. How about this: "Offhand, I''m not sure why that is true (still waking up this fine Monday morning), but I''d recommend throwing this question to the rails mailing list if nobody responds here." -Steve
On Sun, Sep 28, 2008 at 11:59 PM, Nick Hoffman <nick at deadorange.com> wrote:> On 2008-09-28, at 17:20, Nick Hoffman wrote: >> >> 431 it ''should hide the map filter errors <div>'' do >> 432 do_xhr @xhr_params >> 433 response.should have_rjs >> 434 # response.should have_rjs(:hide, ''map-filter-errors'') >> 435 end > > I just discovered that I need to pass :chained_replace_html to #have_rjs , > like so: > response.should have_rjs(:chained_replace_html, :hide, ''map-filter-errors'') > > However, after googling around and looking through the source for > #assert_select_rjs , I have no idea what :chained_replace_html does, nor why > :hide is insufficient. Would someone mind enlightening me?The problem has to do with the javascript that is produced by Rails. You can do things in RJS in one of two ways. Way #1: page[:some_id].hide Way #2 page.hide :some_id Based on which way you go Rails will generate Element.hide(''some_id'') or $(''some_id'').hide() IIRC. assert_rjs uses regular expressions to match against the generated javascript. The fugliness that are these regular expressions require that two different patterns exist to match against the generated javascript correctly. Having chained_replace_html is a hack to separate the regular expressions based on if you used Way #1 or Way #2. I have stopped relying on using RJS selectors to test against generated JavaScript. I have also stopped relying on RJS for the most part, and instead am doing a lot of UJS and JSON (thx Mark VanHolstyn for enlightening me on this). I''m not saying that you shouldn''t do this, but that I''ve hit the problem you''re facing, and I don''t think using regular expressions from the bowels of Rails for asserting against generated javascript is the way to go, -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com
On 2008-09-29, at 13:19, Steve Schafer wrote:> I think it''s a parsing problem, rather than an idiom problem. I > think he > read it as if "offhand" were the object of "that is offhand," which > doesn''t make much sense.Hah, you''re right, Steve =)
On 2008-09-29, at 19:33, Zach Dennis wrote:> Having chained_replace_html is a hack to separate the regular > expressions based on if you used Way #1 or Way #2.Interesting. Thanks for that explanation.> I have stopped relying on using RJS selectors to test against > generated JavaScript. I have also stopped relying on RJS for the most > part, and instead am doing a lot of UJS and JSON (thx Mark VanHolstyn > for enlightening me on this). I''m not saying that you shouldn''t do > this, but that I''ve hit the problem you''re facing, and I don''t think > using regular expressions from the bowels of Rails for asserting > against generated javascript is the way to go,I''ll take a look into UJS and JSON. Were there any articles, blog posts, etc that you found particularly helpful? Cheers, Nick