ghempton / camcorder

VCR not enough? Record arbitrary method invocations for later playback.
MIT License
86 stars 10 forks source link

undefined method `record' for nil:NilClass #11

Closed donv closed 7 years ago

donv commented 7 years ago

Given the code below:

require 'net/imap'
require 'camcorder'

Camcorder.intercept_constructor(Net::IMAP)

imap = Net::IMAP.new('outlook.office365.com', 993, ssl: true)
imap.login('user@example.com', 'password')
imap.select('INBOX')
imap.search(%w(NOT FLAGGED SINCE 21-Dec-2016))
imap.disconnect

I get the following exception:

camcorder-0.0.5/lib/camcorder/proxy.rb:42:in `_record': undefined method `record' for nil:NilClass (NoMethodError)
    from camcorder-0.0.5/lib/camcorder/proxy.rb:52:in `method_missing'
    from cam_test.rb:7:in `<main>'

Is there more setup needed?

lcpriest commented 7 years ago

Hey @donv, the docs don't explain this well.

You need to add a second argument to Camcorder.intercept_constructor.

recorder = Camcorder::Recorder.new('recordings.json')

Alternatively, you can provide a default recorder with:

Camcorder.default_recorder = Camcorder::Recorder.new('recordings.json')

Either way, the issue is that the object is trying to find somewhere to read (or write) your recordings to/form.

donv commented 7 years ago

Thanks for the explanation.