November 18, 2013

Quick tip: Exclude external JavaScript files from your integration tests

Are you using JavaScript in your integration tests?

Then watch out for external JavaScript files in your HTML. Because they can really SLOW DOWN your tests.

If you don't need them in your development and test environment, then include them just in the production environment.

# app/views/layouts/application.html.erb

...
    <% if Rails.env.production? %>
      <script src="http://some-external-script.com/script.sj"></script>
      <script>
        // google analytics code
      </script>
    <% end %>
  </body>
</html>

There is issue mainly with the scripts which are connecting to some external services. Like Google Analytics and so...

If you need to connect to some external services, than it is much more complicated. However check this article for possible solution.

Hey there!

My name is Patrik Bóna and I am the only programmer at Memberful. This blog is kind of dead, but I just started my own Ruby on Rails screencast. Follow me on Twitter if you want to be notified about my newest videos.