Using RSpec with Capybara and Selenium in Rails, I attempted to load custom JS files for drag-drop simulation using this code:
require 'spec/assets/scripts/drag_util.js'
require 'spec/assets/scripts/extra_drag.js'
require 'spec/assets/scripts/drop_controller.js'
but I encounter a LoadError.
Considering the error you encounter, it appears that the approach to load JavaScript files using Ruby’s require statement is not valid for these asset files. I had a similar issue where the custom JS didn’t load because the tests were handling assets differently compared to regular application code. Eventually, I shifted the JS files into the asset pipeline or included them manually through layout modifications when running tests. This method allowed the files to be properly compiled and served to the Selenium browser, addressing the LoadError effectively.
i solved it by ditching the require calls and letting rails asset device handle js. i placed the files in assets and referenced them via application.js, which fixed the load error in selenium tests. might be worth a try if yours ain’t working.