I have a very messy Rails app that I built some time ago that I am currently extending. This has involved a number of major changes to Ruby Version (1.9.x to 2.3.x), Rails Version (3.2.x to 5.0.x), and many other associated changes. It has a lot of cruft and I am uncertain about a lot of things going on in it at the moment.
In order to sort out this horrible mess I have created for myself I have decided to write a bunch of feature tests with RSpec and Capybara. I was making good progress until I needed to test something that used Javascript (eventually most of my feature tests will be testing Javascript).
My Rspec test looks like this so far (there is much left to complete - I just got stuck here);
feature "User registers a new customer", js: true do
scenario "Logged in user registers a new customer" do
user = FactoryGirl.create(:user)
visit_root_and_login user
fill_in 'reg_number', with: '123456'
click_button 'Look up'
end
end
In my app this triggers an AJAX call that looks up the registration number and returns a piece of Javascript that adds additional fields to the form depending on whether the customer has been previously registered or not.
What happens though is this;
Failure/Error: raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
ActionController::RoutingError:
No route matches [GET] "/javascripts/sessions.js"
# /Users/brad/.gem/ruby/2.3.1/gems/railties-5.0.1/lib/rails/rack/logger.rb:36:in `call_app'
# /Users/brad/.gem/ruby/2.3.1/gems/railties-5.0.1/lib/rails/rack/logger.rb:24:in `block in call'
# /Users/brad/.gem/ruby/2.3.1/gems/railties-5.0.1/lib/rails/rack/logger.rb:24:in `call'
# /Users/brad/.gem/ruby/2.3.1/gems/rack-2.0.1/lib/rack/method_override.rb:22:in `call'
# /Users/brad/.gem/ruby/2.3.1/gems/rack-2.0.1/lib/rack/runtime.rb:22:in `call'
# /Users/brad/.gem/ruby/2.3.1/gems/rack-2.0.1/lib/rack/sendfile.rb:111:in `call'
# /Users/brad/.gem/ruby/2.3.1/gems/railties-5.0.1/lib/rails/engine.rb:522:in `call'
# /Users/brad/.gem/ruby/2.3.1/gems/rack-2.0.1/lib/rack/urlmap.rb:68:in `block in call'
# /Users/brad/.gem/ruby/2.3.1/gems/rack-2.0.1/lib/rack/urlmap.rb:53:in `each'
# /Users/brad/.gem/ruby/2.3.1/gems/rack-2.0.1/lib/rack/urlmap.rb:53:in `call'
# /Users/brad/.gem/ruby/2.3.1/gems/capybara-2.12.1/lib/capybara/server.rb:43:in `call'
# /Users/brad/.gem/ruby/2.3.1/gems/rack-2.0.1/lib/rack/handler/webrick.rb:86:in `service'
# ------------------
# --- Caused by: ---
# NameError:
# uninitialized constant Selenium::WebDriver::Remote::W3CCapabilities
# /Users/brad/.gem/ruby/2.3.1/gems/capybara-2.12.1/lib/capybara/selenium/driver.rb:282:in `marionette?'
I tried adding driver: :webkit
to see if anything different happened and got something slightly different;
Failure/Error: raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
ActionController::RoutingError:
No route matches [GET] "/javascripts/sessions.js"
# /Users/brad/.gem/ruby/2.3.1/gems/railties-5.0.1/lib/rails/rack/logger.rb:36:in `call_app'
# /Users/brad/.gem/ruby/2.3.1/gems/railties-5.0.1/lib/rails/rack/logger.rb:24:in `block in call'
# /Users/brad/.gem/ruby/2.3.1/gems/railties-5.0.1/lib/rails/rack/logger.rb:24:in `call'
# /Users/brad/.gem/ruby/2.3.1/gems/rack-2.0.1/lib/rack/method_override.rb:22:in `call'
# /Users/brad/.gem/ruby/2.3.1/gems/rack-2.0.1/lib/rack/runtime.rb:22:in `call'
# /Users/brad/.gem/ruby/2.3.1/gems/rack-2.0.1/lib/rack/sendfile.rb:111:in `call'
# /Users/brad/.gem/ruby/2.3.1/gems/railties-5.0.1/lib/rails/engine.rb:522:in `call'
# /Users/brad/.gem/ruby/2.3.1/gems/rack-2.0.1/lib/rack/urlmap.rb:68:in `block in call'
# /Users/brad/.gem/ruby/2.3.1/gems/rack-2.0.1/lib/rack/urlmap.rb:53:in `each'
# /Users/brad/.gem/ruby/2.3.1/gems/rack-2.0.1/lib/rack/urlmap.rb:53:in `call'
# /Users/brad/.gem/ruby/2.3.1/gems/capybara-2.12.1/lib/capybara/server.rb:43:in `call'
# /Users/brad/.gem/ruby/2.3.1/gems/rack-2.0.1/lib/rack/handler/webrick.rb:86:in `service'
# ------------------
# --- Caused by: ---
# Capybara::ElementNotFound:
# Unable to find field "reg_number"
# /Users/brad/.gem/ruby/2.3.1/gems/capybara-2.12.1/lib/capybara/node/finders.rb:44:in `block in find'
I don't understand why "/javascripts/sessions.js" is being called. I don't have any such file and I don't make this request myself. It looks to be coming from Rack, but this is a zone of the Ruby and Rails world that I really don't understand.
Is anyone able to shed any light on this so I at least know where to start looking?
TIA
OK, I sorted this out.
It was an asset pipeline issue.
In my application.html.haml
I had = javascript_include_tag "application", params[:controller]
which was causing an attempt to include the file /app/assets/javascripts/sessions.js
in my assets during the login process. I had no such file so created a blank one. I then had to add
%w( sessions ).each do |controller|
Rails.application.config.assets.precompile += ["#{controller}.js", "#{controller}.css"]
end
to my /app/config/initializers/assets.rb
to get it all working.
The same exception was being raised in my development environment in the server console but I had not noticed it and it was not stopping execution. In Capybara this exception was stopping the whole show though.