【问题标题】:Rails Feature Tests Failing in Rails 5.0 UpgradeRails 5.0 升级中的 Rails 功能测试失败
【发布时间】:2020-04-09 11:30:40
【问题描述】:

我正在将 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'                                                
end

Gemfile.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 中通过。好奇!

感谢您的帮助。

-约翰C

【问题讨论】:

  • 尝试在您的规范文件中将require spec_helper 更改为require rails_helper
  • hashrocket,谢谢你的帖子。那不是问题所在。请参阅我发布的答案。不过,我很感激你看到这个问题。干杯!保持安全。
  • 从错误页面的内容看来,您可能在测试环境中安装了显示 gem(better_errors 等)的错误详细信息。您应该检查您的 Gemfile 并确保任何类似的 gem 仅在 development 环境中 - 后来 Rails 修复了该默认值。

标签: rspec ruby-on-rails-5 capybara


【解决方案1】:

我终于能够解决这个问题。它最终是由一些“我们认为”添加以处理旧版本 Internet Explorer 的 CSS 条目引起的。当我试图查看规范测试的页面/表单时(在我的开发站点上),我收到了一些奇怪的错误消息。在他们的混合是一个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 &lt; 7 的。删除它解决了这个问题。我使用的应用不是公共应用,我们不使用/不支持旧版本的 IE,因此删除它不是问题。

有点奇怪,这在以前的 rails 版本中不是问题,但 5.0 不喜欢它。

所有功能测试均已通过。

【讨论】:

    猜你喜欢
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-18
    • 2015-05-27
    • 2021-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多