我需要为这个类实现 100% 的代码覆盖率。
我将如何在 simplecov 中测试以下类?
如何在 rspec 中测试 save_user 方法?
class Log < ActiveRecord::Base
has_and_belongs_to_many :tags
has_one :asset
has_one :user
belongs_to :user
after_create :save_user
def save_user
self.user_id = :current_user
self.save()
end
end
describe Log do
context "When saving a user is should save to the database."
it "should call insert fields with appropriate arguments" do
expect(subject).to receive(:asset).with("TestData")
expect(subject).to receive(:user).with("DummyName")
expect(subject).to save_user
subject.foo
end
end