【发布时间】:2016-09-27 03:35:26
【问题描述】:
我需要为这个类实现 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
【问题讨论】:
-
请为您的问题添加更多上下文。
标签: ruby-on-rails rspec simplecov