title: What is a good way for Ruby integration tests to test javascript that does not change the DOM?
body: <p>I am developing a Spree (Ruby on Rails) extension that adds a javascript tag to the page.
  This javascript has no visual or apparant effects for the user; it is a <a href="http://developer.piwik.org/guides/tracking-javascript-guide" rel="nofollow noreferrer">piwik tracking script</a>.</p>
  <p>I want to write some integration tests for this. What is a good way to test javascript that does not change the DOM?</p>
  <h3>Problem: No visual or other DOM changes.</h3>
  <p>Normally, javascript will be tested in the page with code like <code>expect(page).to have_selector 'select.ajax-filled option#detroid'</code> for when a piece of javascript is expected to add a &quot;detroid&quot; option to a select. Yet, in this case, the JS does not change the DOM visually.</p>
  <h3></h3>
  <p>A possible factor to ease this testing, is the fact the <strong>setup</strong> of the tracking-code is simple and predictable. My test does not need to see if running the externally included javascript <code>piwik.js</code> is actually ran correctly.</p>
  <p>My integration tests are good enough when they test that correct <code>_paq.push(['someparam'], 'somevalue')</code> is called. I am not interested in covering all possible ways that some <code>setSiteId</code> can be made available; merely that my code has called or calls <code>_paq.push()</code> with the proper params. But, if testing the effect of the call is easier, I'd gladly pick that.</p>
  <p>Example:</p>
  <pre><code>&lt;script type=&quot;text/javascript&quot;&gt;
      var _paq = _paq || [];
      (function(){ var u=((&quot;https:&quot; == document.location.protocol) ? &quot;https://{$PIWIK_URL}/&quot; : &quot;http://{$PIWIK_URL}/&quot;);
      _paq.push(['setSiteId', {$IDSITE}]);
      _paq.push(['setTrackerUrl', u+'piwik.php']);
      _paq.push(['trackPageView']);
      _paq.push(['enableLinkTracking']);
      var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js';
      s.parentNode.insertBefore(g,s); })();
  &lt;/script&gt;
  </code></pre>
  <p>In this example, I would be interested in:</p>
  <ul>
  <li><code>setSiteID</code> set correctly.</li>
  <li><code>setTrackerUrl</code> has the correct url and protocol.</li>
  <li><code>trackPageView</code> defined.
  etc.</li>
  </ul>
  <h3>Sidenote: not looking for unit-tests, but integration tests.</h3>
  <p>The unit-test side is pretty well covered. This is merely about expecting the correct <code>_paq.push()</code> calls when my extension gets certain configuration options, is integrated in a certain way or used in certain scenarios.</p>
  <h3>So, what testing strategy to take?</h3>
  <p>What should I test against? Regular Expressions? Parsing the JS with a JS parser? Running the JS with a runtime? Some mocking or stubbing trick that I overlooked?</p>