Testing Ajax Calls

Our JavaScript up/down functionality has one more piece: we need to notify the server that the up or down has taken place. That involves making an Ajax call to the server. We probably want to notify the user of success or failure (or at least of failure).

Typically we stub Ajax calls to the server because they’re slow and because they might otherwise require server-side setup to return useful data. We could use plain Jasmine spies for this, or Jasmine’s Ajax framework. Instead I’m going to bring in a different tool that has a slightly higher-level API for managing Ajax.

The tool is called Sinon.[26] It is actually a framework-independent mock-object library, but we’re not going to discuss its generic library, just its fake ...

Get Rails 4 Test Prescriptions now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.