我对Rails中的Rspec测试很新,我正在尝试测试以下内容:
class Event < ApplicationRecord
def host_details
query ||= User.where(id: self.user_id)
end
def hosting_company
company = host_details.first.company
end
end
我有以下规范,但我不确定我应该期待的host_details
方法的结果。我正在使用FactoryGirl。
describe "gets information about the host of an event" do
before(:each) do
@event = build(:event)
end
context "host_details" do
it "querys the event data and finds the associated user" do
end
end
context "hosting_company" do
it "gets the company that is hosting the event" do
expect(@event.hosting_company).to eq "Attnd"
end
end
end