rspec 没有报告错误的行号 [英] rspec not reporting line number of error
问题描述
对于我的几乎所有规范,当 rspec 报告错误时,它会通知我路径末尾的行号,例如
For almost all my specs, when rspec reports an error, it informs me of the line number at the end of the path e.g.
rspec ./spec/controllers/eclubs_controller_spec.rb:21
但是在我的一个规范中,它报告了这样的错误位置
However in one of my specs, it reports the error location like this
rspec ./spec/controllers/eclubs/members_controller_spec.rb[1:1:2:3:1]
这在块的嵌套方面可能有意义,但坦率地说是相当神秘的.
which may make sense in terms of the nesting of blocks but frankly is rather cryptic.
规范的顶部看起来像这样
The top part of the spec that works looks like this
require 'rails_helper'
describe EclubsController do
那个不起作用的看起来像这样
and the one that does not work looks like this
require 'rails_helper'
describe Eclubs::MembersController do
我在这两个文件中看到的唯一区别是,一个控制器是命名空间的,但我还有其他命名空间的控制器可以正确报告错误行.
The only difference I can see in the two files is that one controller is namespaced, but I have other namespaced controllers that report the error line correctly.
这是什么原因造成的?
推荐答案
当行号不够唯一以识别有问题的示例时,RSpec 使用示例 ID.
RSpec uses the example id when the line number is not sufficiently unique to identify the example in question.
这可能发生在动态定义示例时,例如在循环中:
This can happen when examples are dynamically defined, for example in a loop:
(0..10).each do |i|
it do
expect(i).to_not eq(5)
end
end
# rspec './my_spec.rb[1:6]'
或者在使用共享示例组时:
Or when using a shared example group:
RSpec.shared_examples_for "not equal 5" do |i|
it do
expect(i).to_not eq(5)
end
end
RSpec.describe do
it_behaves_like "not equal 5", 5
it_behaves_like "not equal 5", 4
end
# rspec './my_spec.rb[2:1:1]'
这篇关于rspec 没有报告错误的行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!