2

anybody know, how I can stub class variable initialization?

I define

@@connection = Bunny.new.start

for restrict connection numbers, but now I have to test it, and when I try stub it in general way, like

allow_any_instance_of(Bunny).to receive(:start) { something }

it doesn't work. @@ variable initializes earlier.

Also, I can redefine it:

before do
  @@connection = double('conn')
end

but it doesn't suit for me because I have to do not allow create a connection to AMQP

SOLVE

I didn't figure out how to do that, so I used bunny-mock, and it helped me

Oleh Sobchuk
  • 3,612
  • 2
  • 25
  • 41

1 Answers1

1

I don't know if it's bad practice but what about:

YourClass.class_variable_set(:@@variable, 'value')

i. e.

before do
 YourController.class_variable_set(:@@connection, 'value')
end
Pascal
  • 1,158
  • 17
  • 20