我尝试使用 shoulda-matchers 来测试模型之间的关联。但是,它总是显示 Error: TakeTest#test_belongs_to: NoMethodError: undefined method belong_to' for #<TakingTest:0x00007fc14b8e64a8>
test/models/taking_test.rb:8:in
block in ' 我检查了其他答案,其中大多数至少是 4 年前。它仍然适用于rails 6.0吗?
红宝石'2.6.5'
轨道','〜> 6.0.2'
宝石文件
group :development, :test do
gem 'rspec-rails'
end
group :test do
gem 'shoulda', '~> 3.5'
gem 'shoulda-matchers'
end
规范/rails_helper.rb:
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
测试/模型/take_test.rb
class TakingTest < ActiveSupport::TestCase
test "belongs to" do
should belong_to(:students)
end
end