问题:安裝 Should Matchers测试model出现的错误。
group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem "byebug"
  gem "rspec-rails"
  gem "factory_girl_rails"
+  gem "shoulda-matchers", "3.1.1"
end

对应的model

class Course < ActiveRecord::Base
  validates :title, presence: true
end

修改spec/models/course_spec.rb成这样

require "rails_helper"
RSpec.describe Course, type: :model do
  it { is_expected.to validate_presence_of(:title) }
end

输入rspec spec/models/course_spec.rb出现了错误

     NoMethodError:
       undefined method `validate_presence_of' for #<RSpec::ExampleGroups::Course::Validations:0x007fc8ac369120>

没有这个定义。。。google出来的解法是这样的

And this is to add to the top rspec_helper.rb

require 'shoulda-matchers'

require "bundler/setup"
::Bundler.require(:default, :test)

::Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    # Choose a test framework:
    with.test_framework :rspec
    #with.test_framework :minitest
    #with.test_framework :minitest_4
    #with.test_framework :test_unit

    # Choose one or more libraries:
    with.library :active_record
    with.library :active_model
    #with.library :action_controller
    # Or, choose the following (which implies all of the above):
    #with.library :rails
  end
end

参考资料: 12