Say I have this class:
class MyQueue
def initialize
@queue = Queue.new
end
def push(line)
@queue.push(line)
end
end
How should I test that instance variable @queue will receive push method when I call for push on MyQueue instance?
I tried this so far:
describe MyQueue do
let(:my_queue) { instance_double('MyQueue') }
let(:message_line) { double('message_line') }
describe '#push' do
before do
instance_queue = my_queue.instance_variable_set(:@queue, double)
allow(instance_queue).to receive(:push) { message_line }
end
it 'adds line to the queue' do
expect(my_queue.instance_variable_get(:@queue)).to receive(:push) { message_line }
my_queue.push(message_line)
end
end
end
But getting error:
#<InstanceDouble(MyQueue) (anonymous)> received unexpected message :push
with (#<Double "message_line">)
What am I doing wrong?