gpt4 book ai didi

ruby-on-rails - Rspec 共享定义加载两次

转载 作者:行者123 更新时间:2023-12-01 15:44:47 24 4
gpt4 key购买 nike

我无法查明此问题的原因,但我在 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

我的 spec_helper 看起来像这样:

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

这是我收到的弃用警告:

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.

我不需要在测试套件中的任何其他地方(无论如何我都能找到)这些共享规范。我查看了 rspec-core,发现有很多我不太了解的元编程。

有人知道如何调试吗?

最佳答案

我相信原因已描述here .由于您的文件名以“_spec.rb”结尾,它们会被 RSpec 自动加载为示例。我所做的和有帮助的是重命名文件,包含共享示例,删除“_spec”部分。

关于ruby-on-rails - Rspec 共享定义加载两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27256107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com