In my Rails application, I have a .js.erb file that has a variable that is dynamically set based on some Ruby code.
var myTimer = <%= MyApp.config.timeout_time * 1000 %>;
The application works fine, but I have problems with some automated tests. The problem arises in the RSpec test, which works with this JavaScript. There are several tests in my specification file that change the ruby ββtime of MyApp.config.timeout_time on the fly to test various scenarios. In my spec file, the first example passes and the rest fail.
I finally realized that this was happening because myTimer never updated by JavaScript. When the first test runs, JavaScript compiles using the current value set in Ruby. When I change the Ruby timer for the second test, RSpec still uses the previous value in JavaScript.
Is there a way to tell Sprockets / Rails that the file or part of the cache is invalid so that JavaScript is rebuilt? I don't want to disable caching altogether, I just need a way to invalidate application.js based on each test, if necessary.
I can βtouchβ one of the JavaScript files in the file system to make the stars think the file has been modified, but I really don't want to.
source share