在我的模型中,我redefine_associations!在執行期間運行該方法:
# frozen_string_literal: true
class MyModule < AnotherModule
redefine_associations!
end
class AnotherModule < ApplicationRecord
def self.redefine_associations!
belongs_to :user
end
redefine_associations!
end
如何測驗我的模型是否具有redefine_associations!.
我嘗試了以下不起作用:
# frozen_string_literal: true
RSpec.MyModule VisitDate do
it { expect(subject).to have_received(:redefine_associations!) }
it { should respond_to(:redefine_associations!) }
end
uj5u.com熱心網友回復:
由于這是一個宏方法,因此最簡單的測驗方法是:
let(:class_file_array) do
File.readlines(Rails.root.join('app/models/my_module.rb'))
end
it 'calls redefine_associations!' do
expect(class_file_array.include?(" redefine_associations!\n")).to be true
end
uj5u.com熱心網友回復:
據我了解,您想檢查是否redefine_associations為該模型定義了該方法。然后你可以這樣做:
it { expect(subject.methods.includes?(:redefine_associations!)).to eql(true) }
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/498041.html
上一篇:捆綁安裝運行兩次
