1.安装
group :test do
gem 'shoulda-matchers'
end
2.配置
touch spec/support/shoulda_matcher.rb
- 内容:
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
3.使用
RSpec.describe Person, type: :model do
it { is_expected.to validate_presence_of(:name) }
end