thoughtbot/capybara-webkit — pull request #595 by eagletmt (2013-12-03 01:12:56+00:00)
Title: Fix random Capybara::Webkit::InvalidResponseError failure

This pull-request fixes the random Capybara::Webkit::InvalidResponseError failure described in #550.

The problem is a kind of "time of check to time of use" issue. The current webkit checks the validity of node index *before* actual `Node` command.
https://github.com/thoughtbot/capybara-webkit/blob/f35e2df0df3b2e253d78ab96afa670662f862037/lib/capybara/webkit/node.rb#L128-L134
But it could be broken in the following scenario:

1. Check the validity of index by sending `Node isAttached`.
2. The index becomes invalid by DOM mutation or asynchronous redirection, etc..
3. Send actual `Node` command to the index which is no longer valid.

My pull-request makes the validity check atomic. By checking each time in JavaScript and throw `NodeNotAttachedError` from JavaScript, "time of check to time of use" issue should be fixed.