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

Lee Lee.Longmore at googlemail.com
Tue May 12 10:09:15 EDT 2009


Thanks Philip.

I should have added in my original post that I have included the
Webrat::Matchers as instructed in The Rspec Book.

Unless I have misunderstood you, it appears that RSpec with
Webrat::Matchers do not support the driving out of AJAX functionality
in views, hence the need to use Nokogiri. Is my understanding correct?
Or is this your preferred approach but there are others?

On May 12, 2:42 pm, Phlip <phlip2... at gmail.com> wrote:
> Lee Longmore wrote:
> > I am new to RSpec and have just started to drive out my first Rails view
> > using a spec. I have used the The RSpec Book (beta) to do the basic
> > stuff like testing for the presence of a field but I am unsure where to
> > start for driving out some AJAX functionality.
>
> To test the onchange='' of the field, start by pulling in the Test::Unit
> versions of the assertions:
>
>    Spec::Runner.configure do |c|
>      c.include Test::Unit::Assertions
>    end
>
> Now use assert_xhtml to grab your edit field and return it as a Nokogiri node.
> This line does it for a <a href='#'>All</a>:
>
>      a = assert_xhtml{|x|  x.a 'All', :href => '#'  }
>      assert{ a[:onclick] =~ /new Ajax.Request.*xhr_run_all/ }
>
> .send_js_to is supposed to work in the second line, but I have not yet
> researched out how get rkelly to parse the Ajax.Request line.
>
> The point of using rkelly inside send_js_to (aka assert_rjs_) is it's a real
> JavaScript lexer, not a Regexp, so when I get it working it will be very accurate!
>
> --
>    Phlip
>    http://flea.sourceforge.net/resume.html
>
> _______________________________________________
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users


More information about the rspec-users mailing list