title: How to force scripts to load before interpreting html in Rails Capybara JS tests
body: <p>In my file <code>dances.html.erb</code>, my test complains:</p>
  
  <pre><code>Failures:
  
    1) Creating dances creates a new dance with non-javascript data
       Failure/Error: visit '/dances/new'
  
       Capybara::Poltergeist::JavascriptError:
         One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details).
  
         ReferenceError: Can't find variable: $
         ReferenceError: Can't find variable: $
             at http://127.0.0.1:33842/dances/new:81 in global code
  </code></pre>
  
  <p>I think the offending html code looks like</p>
  
  <pre><code>&lt;script&gt;
  
    $( "#choreographer-autocomplete" ).autocomplete({
      source: &lt;%= a_to_safe_str(Choreographer.all.map &amp;:name) %&gt;,
      autoFocus: true,
      minLength: 0
    });
    $( "#start-type-autocomplete" ).autocomplete({
      source: ["improper","Becket","Becket ccw","four face four","square dance","indecent"],
      autoFocus: true,
      minLength: 0
    });
  &lt;/script&gt;
  </code></pre>
  
  <p>and the offending calls to '$' are here. 
  I think this means JQuery isn't loading?
  If I snip them, then the next error is:</p>
  
  <pre><code> Failure/Error: JSON.parse self.figures_json
  
   ActionView::Template::Error:
     784: unexpected token at '{{toJson(figures.arr)}}'
  </code></pre>
  
  <p>Those handlebars are an Angular thing. 
  Is Angular also not loading?</p>
  
  <p>Here's my Rails application.js:</p>
  
  <pre><code>//= require angular
  //= require jquery
  //= require bootstrap-sprockets
  //= require jquery_ujs
  //= require_tree .
  
  //= require jquery-ui/autocomplete
  //= require angucomplete-alt
  </code></pre>
  
  <p>This works fine in the Real World, just not in this test. </p>
  
  <p>Is there something I need to do to get these JS libs to load before the body html is executed?</p>