vendredi 18 février 2022

how to check if a method is called or not in rspec

as i try to check internally my method was calling or not in rspec but it got the following errors


context "#Meeting_schedule" do
    let(:meeting_schedule) { FactoryGirl.create(:meeting_schedule,:time=>"morning",:schedule_name=>"planned_meet", :schedule_info=>[{ "from"=>"00:00", "to"=>"00:01"}]) }

    it "if the same schedule was created again dont save it again" do 
      schedule.save
      params = {:time=>"morning",:schedule_name=>"planned_meet", :schedule_info=>[{ "from"=>"00:00", "to"=>"00:01"}]}
      meeting_schedule.create_or_update_meeting_schedule(params)
      expect(meeting_schedule).to receive(:updating_the_user)
    end
  end


i got the following error

Failure/Error: expect(meeting_schedule.create_or_update_meeting_schedule(params)).to receive(:updating_the_user)
       (#<Meeting_schedule:0x0055dbaf0da710>).updating_the_user(*(any args))
           expected: 1 time with any arguments
           received: 0 times with any arguments
     # ./spec/models/meeting_schedule_spec.rb:122:in `block (4 levels) 

so what was wrong in my code?

my method

def create_or_update_meeting_schedule(params)
   self.attributes = params
   if self.changed and self.save
     updating_the_user
   end
   self
end

can anyone help me out

Aucun commentaire:

Enregistrer un commentaire