Rspec 'it { should have_db_column(:x).of_type(:y) }' 不工作

Rspec 'it { should have_db_column(:x).of_type(:y) }' not working

我的 attendance_rspec.rb 文件包含:

require "rails_helper"

RSpec.describe Attendance, type: :model do
    it { should have_db_column(:date).of_type(:date) }
end

当我 运行 从终端使用 rspec spec/models/attendance_spec.rb

显示错误:

Failures:

  1) Attendance 
     Failure/Error: it { should have_db_column(:date).of_type(:date) }

     NoMethodError:
       undefined method `of_type' for #<RSpec::Matchers::BuiltIn::Has:0x000055e5c65dd3e0>
     # ./spec/models/attendance_spec.rb:4:in `block (2 levels) in <main>'

我已经配置了 FactoryBot 以及 database_cleanercapybara gem。我缺少什么 gem 或 rails_helper.rb 中缺少什么配置?

我按照 this link 设置 Rspec

作为 NickM pointed out, the have_db_column matcher is provided by the shoulda-matchers gem. Add it to your Gemfile and follow the integration steps 使用 have_db_column