我正在将一个rails应用程序从4.2升级到5.0。我们使用的是ruby 2.6.4
我的功能测试在4.2上运行得很好,但现在在5.0上却失败了。我还没能在谷歌上找到任何关于这方面的信息。在我看来,功能测试似乎看不到页面。
Gemfile:
group :test do
gem 'factory_girl'
gem 'factory_girl_rails'
gem 'capybara'
gem 'faker'
gem 'mocha', require: false
gem 'webmock', require: false
gem 'simplecov'
gem 'rails-controller-testing'
endGemfile.lock显示了我玩过的水豚的几个不同版本的capybara (3.32.1),但我得到了相同的结果。
功能测试:
require 'spec_helper.rb'
RSpec.feature "Manage Account Codes" do
scenario "User creates a new Account Code" do
# go to the new account code form
visit new_admins_kuali_account_code_path
# should be success
expect(page.status_code).to eq(200)
# are we on the right page/form?
expect(page).to have_content("Use this form to add a new account code")
end
...
end失败:
Manage Account Codes
User creates a new Account Code (FAILED - 1)
Failures:
1) Manage Account Codes User creates a new Account Code
Failure/Error: expect(page).to have_content("Use this form to create a new account code")
expected to find text "Use this form to create a new account code" in "Kuali Account Codes\n| | \"kuali_account_codes\", :action => \"index\") %> | | | | 'layouts/statlerwire' %>"
# ./spec/features/kuali_account_code_spec.rb:19:in `block (2 levels) in <top (required)>'
Finished in 1.45 seconds (files took 2.7 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/features/kuali_account_code_spec.rb:11 # Manage Account Codes User creates a new Account Code第一个测试:expect(page.status_code).to eq(200)通过。我注释掉了其他的,所以只有它可以运行。它似乎到达了page,但它在页面上看不到/找不到任何其他东西。我是不是错过了rails 5.0所需的宝石
如前所述,所有功能测试都是在4.0中通过的。好奇心!
谢谢你的帮助。
-johnC
发布于 2020-04-10 23:23:42
我终于能够解决这个问题了。它最终是由一些CSS条目引起的,“我们相信”是为了处理旧版本的Internet Explorer而添加的。当我试图查看规范测试的页面/表单(在我的开发站点上)时,我收到了一些奇怪的错误消息。在它们的混合中有一个css文件的语法错误:... found ; expecting }我遇到了这个:
从css文件:
table.display thead th {
padding: 3px 10px;
border-bottom: 1px solid black;
font-weight: bold;
cursor: pointer;
* cursor: hand;
}星号*是错误所在。2011年的一条提交消息指出这是针对* property: set the value in IE < 7的。移除它就解决了问题。我正在使用的应用程序不是公共应用程序,我们不使用/支持旧版本的IE,因此删除它不是问题。
这有点奇怪,这在以前的rails版本中不是问题,但5.0不喜欢它。
所有功能测试均通过。
https://stackoverflow.com/questions/61120164
复制相似问题