A project I’m working on fetches data from a 3rd party service and caches it locally along with specific info for my app.
My environment:
- I provide a search mechanism against the service’s search API.
- When a user browses to the item page for the first time, the my server fetches the info from the service and stores it
- On subsequent requests the browser just requests the information from my server
.. however.. I want info from the 3rd party service to stay up to date.
My plan (feedback welcome!)
- On a subsequent request after page load, some JS will ping the 3rd party service to check for updates
- If the item has been updated, push an update to my copy server side
How to test this?
When I write a controller spec I don’t think the page’s javascript is executed (to fetch the since-updated item from the service)
I had quite a bit of trouble trying to describe this so a diagram might help.

Technology I’m using: Rails/RSpec/Factory Girl/JQuery
It looks like there are a few ways to test this assuming my current solution.
Thoughtbot makes a library called capybara-webkit that will spin up webkit in the background and render/run your tests through it. Selenium is another.
github link
blog post
back on this project after a bit of a hiatus.. using capybara and :js => true seems to work – some tricky timing issues, but otherwise good to go