我有一个非常凌乱的Rails应用程序,我之前建立的,我目前正在扩展。这涉及Ruby版本(1.9.x到2.3.x),Rails版本(3.2.x到5.0.x)以及许多其他相关更改的一些重大更改。它有很多不妥之处,我不确定目前正在发生的很多事情。
为了理清我为自己创造的这个可怕的混乱,我决定用RSpec和Capybara写一堆功能测试。在我需要测试使用Javascript的东西之前,我取得了很好的进展(最终我的大多数功能测试都将测试Javascript)。
到目前为止,我的Rspec测试看起来像这样(还有很多东西需要完成 - 我刚刚被困在这里);
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
在我的应用程序中,这会触发一个AJAX调用,该调用会查找注册号并返回一段Javascript,它会根据客户之前是否已注册而向表单添加其他字段。
虽然这是怎么回事;
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?'
我尝试添加driver: :webkit
以查看是否发生了任何不同的事情,并且略有不同;
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'
我不明白为什么要调用“/javascripts/sessions.js”。我没有任何此类文件,我自己也没有提出此请求。它看起来来自Rack,但这是Ruby和Rails世界的一个区域,我真的不明白。
是否有人能够对此有所了解,所以我至少知道从哪里开始寻找?
TIA
答案 0 :(得分:1)
好的,我把它排除了。
这是一个资产管道问题。
在我的application.html.haml
我= javascript_include_tag "application", params[:controller]
导致尝试在登录过程中将文件/app/assets/javascripts/sessions.js
包含在我的资产中。我没有这样的文件所以创建一个空白的文件。然后我不得不添加
%w( sessions ).each do |controller|
Rails.application.config.assets.precompile += ["#{controller}.js", "#{controller}.css"]
end
到我的/app/config/initializers/assets.rb
,让它全部正常工作。
在我的服务器控制台的开发环境中引发了同样的异常,但我没有注意到它并且它没有停止执行。在Capybara,这个例外正在停止整个节目。