mercredi 25 avril 2018

test that method was called inside another method with rspec

I have to write a spec for the following method:

def track_event
  tracker = set_tracker
  category = define_event_category
  tracker.event(category: category, action: name, label: properties['short_name'], value: properties['paid'])
end

To be specific I have to to check if method event is called on the variable tracker when track_event is called. I tried to do it like this:

describe '#track_event' do
  it 'should call event method' do
    expect(tracker).to receive(:event)
  end
end

and got an error undefined local variable or method 'tracker'. What do I do wrong?

Aucun commentaire:

Enregistrer un commentaire