【发布时间】:2018-05-18 21:30:31
【问题描述】:
我正在尝试将 Capybara 用作前端测试套件 (Vue),但我从 Puma 收到以下错误:
Failure/Error: raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
ActionController::RoutingError:
No route matches [GET] "/login"
这是什么原因,我该如何解决?是不是跟配置有关?让我知道是否应该在我的问题中包含更多代码。
rails_helper.rb:
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
require "pundit/rspec"
require "capybara/rails"
require "capybara/rspec"
require "capybara/poltergeist"
require 'database_cleaner'
require 'factory_girl'
require 'shoulda/matchers'
require "paperclip/matchers"
require 'support/spec_helpers/warden_controller_helpers'
require 'webmock/rspec'
require 'support/spec_helpers/webmock_helper'
Capybara.javascript_driver = :poltergeist
login_spec.rb:
require 'rails_helper'
RSpec.feature "User login", type: :feature, js: true do
before :each do
@user = User.create!(
first_name: "Bob",
last_name: "Brown",
email: "bob@email.com",
password: "bob1",
has_accepted_terms: true
)
end
scenario "User logs in with correct credentials" do
visit root_path
save_screenshot
click_on 'Log In'
sleep 1
save_screenshot
end
end
【问题讨论】:
-
需要更多信息以进行故障排除。什么是创建“/登录”路线?是设计吗?我们可以看看你的路线文件吗?当您在本地浏览器中尝试时,这是否有效?
-
将运行
rails routes的输出添加到您的问题中。 -
我在 routes.rb 中没有 /login 路由,我使用 vue 路由器来渲染 Login.vue 组件。我是否使用适当的库来测试我的情况?现在一切都在浏览器中运行。
-
是否所有的 vue JS 文件都被转译和填充以兼容 Capybara.javascript_driver = :selenium_chrome_headless 作为起点,直到您需要自定义驱动程序注册)
-
@ThomasWalpole 我刚刚尝试使用以下方法进行设置:drivy.engineering/running-capybara-headless-chrome 我仍然遇到同样的错误,我应该注意哪些细微差别?
标签: ruby-on-rails vue.js rspec capybara puma