测试:如何访问"model_has_error_on_field"?

Testing: how to access "model_has_error_on_field"?

我在看 Mastodon 测试来寻找灵感,我注意到他们 User model tests 上的这个 model_has_error_on_field 方法。

任何人都知道这个方法是从哪里定义的以及我如何在我的测试套件中访问它?

找到了,这是在mastodon/spec/support/matchers/model/model_have_error_on_field.rb

中定义的自定义Rspec::Matchers
如果你想使用它:
Dir[Rails.root.join('spect', 'support', '**', '*.rb')].sort.each { |f| require f }