Rspec共享定义加载两次

meh*_*kar 2 rspec ruby-on-rails rspec-rails

我无法确定原因,但我收到了在Rails项目中多次加载共享规范的弃用警告.以下是它们的定义方式:

#spec/support/shared/authenticated_endpoints_spec.rb

RSpec.shared_examples "an authenticated endpoint" do
  it_behaves_like "an authenticated show endpoint"
  it_behaves_like "an authenticated index endpoint"
end

RSpec.shared_examples "an authenticated show endpoint" do
# omitted
end
RSpec.shared_examples "an authenticated index endpoint" do
# omitted
end
Run Code Online (Sandbox Code Playgroud)

spec_helper看起来像这样:

RSpec.configure do |config|
  Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
end
Run Code Online (Sandbox Code Playgroud)

这是我得到的弃权警告:

WARNING: Shared example group 'an authenticated endpoint' has been previously defined at:
  /Users/me/my_proj/spec/support/shared/authenticated_endpoints_shared_spec.rb:1
...and you are now defining it at:
  /Users/me/my_proj/spec/support/shared/authenticated_endpoints_shared_spec.rb:1
The new definition will overwrite the original one.
WARNING: Shared example group 'an authenticated show endpoint' has been previously defined at:
  /Users/me/my_proj/spec/support/shared/authenticated_endpoints_shared_spec.rb:6
...and you are now defining it at:
  /Users/me/my_proj/spec/support/shared/authenticated_endpoints_shared_spec.rb:6
The new definition will overwrite the original one.
WARNING: Shared example group 'an authenticated index endpoint' has been previously defined at:
  /Users/me/my_proj/spec/support/shared/authenticated_endpoints_shared_spec.rb:36
...and you are now defining it at:
  /Users/me/my_proj/spec/support/shared/authenticated_endpoints_shared_spec.rb:36
The new definition will overwrite the original one.
Run Code Online (Sandbox Code Playgroud)

我不需要在测试套件中的任何其他地方(我可以找到,无论如何)找到这些共享规范.我查看rspec-core了很多元编程,我不太明白.

任何人都有关于如何调试这个的提示?

The*_*ent 5

我相信原因在这里描述.由于您的文件名以"_spec.rb"结尾,因此它们将作为RSpec的示例自动加载.我做了什么和有什么帮助,重命名文件,包含共享示例,删除"_spec"部分.