[rspec-users] How To Drive Out AJAX Functionality in a Rails View

Matt Wynne matt at mattwynne.net
Tue May 12 12:01:27 EDT 2009

On 12 May 2009, at 16:33, Lee wrote:

> Thanks Matt.
> I have been trying out Cucumber and Culerity (Celerity) but rather
> than jump directly from Cucumber to coding the necessary views,
> controllers and models required for each scenario, I wanted to drive
> out the code using RSpec. So I've started to spec a view required by a
> scenario, and this is where I am confused about how I approach the
> AJAX aspects of the view in my specs.

If you're using progressive enhancement though, I wouldn't expect the  
views themselves to be any different - the code to add javascript  
behaviour is all in external js files. I'd personally recommend doing  
that over using the rails js generators that squirt behaviour into  
your onclick events. eugh.

>> One thing you might want to consider is looking at using a headless
>> browser like 'celerity' for testing your ajax code. This is quite a
>> bit more involved for initial setup than using RSpec but will give  
>> you
>> real confidence as you're actually running your javascript inside a
>> browser. There are quite a few people on this list who are doing  
>> this,
>> using the 'progressive enhancement'[1] pattern to build a version of
>> the page that works with raw HTML, then decorate it with javascript
>> behaviour when the page loads.
>> I'm not doing this myself in earnest, so I'll say no more, but
>> hopefully a couple of other people will chime in with some advice.
>> [1]http://en.wikipedia.org/wiki/Progressive_enhancement
>> Matt Wynnehttp://blog.mattwynne.nethttp://www.songkick.com
>> _______________________________________________
>> rspec-users mailing list
>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

Matt Wynne

More information about the rspec-users mailing list