# What is :chained\_replace\_html?

**URL:** <https://www.ruby-forum.com/t/what-is-chained-replace-html/149772>\
**Category:** Rails\
**Created:** [September 29, 2008, 4:58pm UTC](https://www.ruby-forum.com/t/what-is-chained-replace-html/149772 "2008-09-29T16:58:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7ea924/32.png) [@nickh](https://www.ruby-forum.com/u/nickh)\
**Post date:** [September 29, 2008, 4:58pm UTC](https://www.ruby-forum.com/t/what-is-chained-replace-html/149772/1 "2008-09-29T16:58:06Z")

</div>

# I’m testing an XHR, and until I discovered :chained\_replace\_html , the test wasn’t seeing that a was being hidden. === map\_filter.rjs 22 page[‘map-filter-errors’].hide # Why does line 433 above fail?: === neighbourhoods\_controller\_spec.rb 432 do\_xhr @xhr\_params 433 assert\_select\_rjs :hide === The test’s output No RJS statement that replaces or inserts HTML content. # But when I change the test to this, the test succeeds: === neighbourhoods\_controller\_spec.rb 432 do\_xhr @xhr\_params 433 assert\_select\_rjs :chained\_replace\_html I’ve googled around, read the source for #assert\_select\_rjs , but can’t figure out what :chained\_replace\_html is, means, when it should be used, etc. So, I have three questions: 1. Why does passing :hide to #assert\_select\_rjs fail to see the RJS change? 2. What is :chained\_replace\_html ? 3. When should :chained\_replace\_html be used? Thanks! Nick

---

<div class="post-metadata">

**Author:** ![nickh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7ea924/32.png) [@nickh](https://www.ruby-forum.com/u/nickh)\
**Post date:** [October 1, 2008, 9:53am UTC](https://www.ruby-forum.com/t/what-is-chained-replace-html/149772/2 "2008-10-01T09:53:37Z")

</div>

On the rspec-users mailing list, Zach D. had a great response to  
my question:

* * *

On Sun, Sep 28, 2008 at 11:59 PM, Nick H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
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?

On 2008-09-29, at 19:33, Zach D. wrote:  
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 D. [http://www.continuousthinking.com](http://www.continuousthinking.com) [http://www.mutuallyhuman.com](http://www.mutuallyhuman.com)
