为什么 RSpec 会抛出 InvalidSignature 错误?

Why RSpec throws an InvalidSignature error?

我是 Ruby、Rails 和 TDD 的新手,我在测试代码时遇到了困难。 我正在尝试测试 Recipe 模型的创建,该模型由使用 FactoryBot 创建的用户发布。

我的食谱模型 (app/models/recipe.rb) 是:

class Recipe < ActiveRecord::Base
  resourcify

  validates :image, presence: true
  validates :title, presence: true
  validates :preparazione, presence: true

  belongs_to :user
  has_many :likes
  has_many :comments

  has_one_attached :image
end

在 spec/models/recipe_spec.rb 我有:

require "rails_helper"

RSpec.describe Recipe, type: :model do
  describe "Creating a Recipe" do
    it "should be permitted" do
  
      @user = FactoryBot.create(:user)
      recipe = Recipe.new(title: 'Recipe', 
                          preparazione: 'Preparation',
                          image: '../support/test_image.jpg',
                          user_id: @user.id,
                          n_likes: 0,
                          n_comments: 0,
                          created_at: Time.now.utc)
      expect(recipe).to be_valid
      @user.destroy
    end
  end
end

本次测试失败,错误为:

Failures:

1) Recipe Creating a Recipe should be permitted
 Failure/Error: expect(recipe).to be_valid

 ActiveSupport::MessageVerifier::InvalidSignature:
   ActiveSupport::MessageVerifier::InvalidSignature
 # ./spec/models/recipe_spec.rb:16:in `block (3 levels) in <top (required)>'

 Finished in 0.35273 seconds (files took 7.93 seconds to load)
 7 examples, 1 failure

 Failed examples:

 rspec ./spec/models/recipe_spec.rb:5 # Recipe Creating a Recipe should be permitted

为什么会出现此错误,这是什么意思?

recipe = Recipe.new(title: 'Recipe', 
                          preparazione: 'Preparation',
                          image: Rack::Test::UploadedFile.new('spec/support/test_image.jpg', 'image/jpg')), 
                          user_id: @user.id,
                          n_likes: 0,
                          n_comments: 0,
                          created_at: Time.now.utc)

在 Rspec 中使用 Rack::Test::UploadedFile class 上传附件。