Mojím cieľom je napísať rspec test, ktorý skontroluje, či bola metóda volaná.
notify(result) if notification_allowed?(result)
Obaja sú oznámené? a upozornenie sú súkromné metódy. Presnejšie potrebujem test, ktorý overí, či sa zavolala metóda oznamovania. Snažil som sa urobiť niečo ako nižšie, ale zdá sa, že nie je správne.
subject { described_class.new }
it do
expect(subject).to receive(:notify)
subject.send(:notification_allowed?, true)
end
odpovede:
2 pre odpoveď č. 1povolania notification_allowed?
nerobí nič okrem návratu výsledku notification_allowed?
Nesúvisí to notify
Mali by ste zavolať funkciu, ktorá obsahuje výraz, ktorý chcete otestovať.
Metóda môže byť napríklad ...
def check_and_notify(result)
notify(result) if notification_allowed?(result)
end
takže test by bol ...
subject { described_class.new }
it "calls notify" do
expect(subject).to receive(:notify)
subject.send(:check_and_notify, true)
end