[rspec-users] How To Drive Out AJAX Functionality in a Rails View
Lee.Longmore at googlemail.com
Tue May 12 11:06:30 EDT 2009
fyi, I am trying out Cucumber and Culerity for integration testing.
Culerity provides for AJAX testing.
Having written my first Cucumber (with Culerity) feature and set of
scenarios, I was keen to then use RSpec to begin driving out the
views, controllers etc so that I can eventually run the e2e Cucumber
On May 12, 3:04 pm, Mike Doel <m... at mikedoel.com> wrote:
> On May 12, 2009, at 8:36 AM, 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.
> Check out Adam McCrea's fork of webrat:
> It includes a submit_form_via_ajax method that I use to do this. It
> basically just forces Rails into treating the form request as asking
> for a .js response. There are limitations on what you can do with the
> response (e.g. inspecting the entire page is no longer possible), but
> you are able to look at the response body of the call and match it
> against regular expressions. So, I use features like:
> When I go to the homepage
> And I use a search term of "foo"
> And I press "search"
> And the edit_search_form is submitted via ajax
> Then the search results should have 2 bars
> with the critical step like:
> When /^the (.+) is submitted via ajax$/ do |form|
> submit_form_via_ajax form
> I've left out a couple of things here (in particular, a step that
> makes it possible to have acceptance tests for ajax based features
> that are written in the language of the customer and yet operate
> quickly (i.e. you don't need to have selenium or something else like
> that involved to run this).
> The drawback of course is that it's not really exercising the full end-
> to-end system. While I understand that this is frowned upon (and for
> good reason), in my case, I have decided that the speed of the tests
> (and thus my willingness to use them) makes up for the drawbacks
> unit tests that will ensure that the behavior I stub out above
> actually works as expected.
> Mike Doel
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
More information about the rspec-users