在运行Cucumber测试时,它会不时地间歇性地失败.错误是:
*** ActionView::Template::Error Exception: Missing partial items/_fields with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :haml]}. Searched in:
* "/my/path/to/application/app/views"
* "/my/path/to/rvm/gems/ruby-2.1.5/gems/kaminari-0.16.3/app/views"
* "/my/path/to/rvm/gems/ruby-2.1.5/gems/devise-3.5.4/app/views"
Run Code Online (Sandbox Code Playgroud)
是的,部分文件确实存在于 /my/path/to/application/app/views/items/_fields.html.haml
踢球者有时候测试会通过,有时候会失败.我在Red Hat 5机器上运行.
所以为了调试这个,我决定投入一个begin/rescue.
.fields
- begin
= render partial: 'items/fields', locals: {f: f}
- rescue Exception => e
= byebug
- if f.can_modify?(:object_a)
= render partial: 'layouts/object_a_field', locals: {f: f, field: :object_a}
- else
.field#object_a
= render partial: 'layouts/attribute', locals: {label: 'Object A', value: f.object.object_a_id ? f.object.object_a_number : 'Not Assigned'}
.field#name
- if f.can_modify?(:name)
= f.label :name
= f.text_field :name, {class: 'inputbox large_field', readonly: f.cannot_modify?(:name)}
.smltxt (short description of the item)
- else
= render partial: 'layouts/attribute', object: f.object, locals: {field: :name}
Run Code Online (Sandbox Code Playgroud)
对于那些好奇的东西items/fields:
.field
- if f.can_modify?(:name)
= f.label :name, 'Item'
= f.text_field :name, {class: 'inputbox uppercase', maxlength: 16, readonly: !f.object.identifier.new_record?}
.smltxt (character identifier)
- else
= render partial: 'layouts/attribute', object: f.object, locals: {field: :name, label: 'Item'}
Run Code Online (Sandbox Code Playgroud)
当它通过时,我显然不会碰到这个小动物,但是当它失败时,我会这样做!这允许我在Rails控制台类型环境中使用它.
所以我决定运行那个特定的命令:
(byebug) render partial: 'items/fields', locals: {f: f}
Run Code Online (Sandbox Code Playgroud)
我得到:
*** ActionView::Template::Error Exception: Missing partial items/_fields with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :haml]}. Searched in:
* "/my/path/to/application/app/views"
* "/my/path/to/rvm/gems/ruby-2.1.5/gems/kaminari-0.16.3/app/views"
* "/my/path/to/rvm/gems/ruby-2.1.5/gems/devise-3.5.4/app/views"
Run Code Online (Sandbox Code Playgroud)
所以我想我会删除当地人,看看是否有任何改变:
(byebug) render partial: 'items/fields'
Run Code Online (Sandbox Code Playgroud)
我得到:
*** ActionView::Template::Error Exception: undefined local variable or method `f' for #<#<Class:0x0000002a907610>:0x00000027beae48>
Run Code Online (Sandbox Code Playgroud)
所以很明显它现在神奇地找到了部分,它知道它缺少一个局部变量f.
更新1
为了清楚起见,我添加了上面调用部分视图的其余视图.
为了排除故障,我还把items/_fields.html.haml它的内容放在我所拥有的地方render partial: 'items/fields', locals: {f: f}......然后测试通过,这意味着文件中的其他部分也没有问题.所以它似乎与文件的内容无关.
更新2
似乎通过在我们的第一个Cucumber功能中添加@javascript标记经常修复此问题.以某种方式在其他测试之前加载浏览器,提高了传递的机会.对我没有任何意义,也许别人对此有所了解?
更新3
今天已经发现这个错误根本与黄瓜无关.在生产中发现了同样的错误.Web界面显示Missing Partial错误,但对于确实存在的文件.使用后重新启动Passenger服务器,touch tmp/restart.txt然后错误消失.所以它仍然是非常间歇性的.
更新4
我添加了似乎随机丢失的部分内容.
我怎么去发现为什么Rails找不到实际存在的部分?
我坚信升级到 Ruby 2.3.1 为我们解决了这个问题。我不确定可能发生了什么变化。当我们调查这个问题时,我和我的同事认为我们在 Rails 源代码中发现了一行,该行根据 Ruby 版本以不同的方式呈现部分。
我现在很难找到这个问题,但我仍然想指出,自从我们升级到较新的 Ruby 后,问题似乎就消失了。