问题
I'm quite new to Rspec testing in Rails and I'm trying to test the following:
class Event < ApplicationRecord
def host_details
query ||= User.where(id: self.user_id)
end
def hosting_company
company = host_details.first.company
end
end
I have the following spec but I'm not sure exactly what I'm supposed to be expecting back for the results of the host_details
method. I'm using 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
来源:https://stackoverflow.com/questions/39035668/testing-where-queries-in-rspec-rails