我一直未能找出原因,但我得到的是在Rails項目中多次加載共享規格的棄用警告。下面是他們是如何定義的:Rspec共享定義加載兩次
#規格/支持/共享/ 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
,還有很多元編程正在進行,我不太明白。
任何人都有關於如何調試的提示?
不知道我明白。如果我刪除加載我的'spec_helper'中的文件的行,則會收到這些共享規範的未找到錯誤。或者,如果我將共享的規格移出到「spec/shared」,我仍然必須以某種方式加載它們,對吧? – mehulkar 2014-12-22 17:14:12
我已將它們移至'spec/shared',並且單獨要求共享規格在哪裏使用。不知道這是否是最好的解決方案。 – mehulkar 2014-12-22 17:14:42
也必須從每個共享示例文件中刪除'_spec'。 – mehulkar 2014-12-22 17:23:54